可变范围问题(nodejs / javascript)

时间:2018-06-23 23:20:29

标签: javascript node.js reactjs react-native

如果变量 value 是全局变量,为什么当我 console.log()从socket.on('Led_1')中退出时却未定义? `

var io = require('socket.io-client');
var value;
var socket = io.connect('http://105.155.150.85/');

socket.on('Led_1',function(data){
    value = data.message;
    console.log(value); // Here it shows the value.
});

console.log(value); // here it shows undefined.

`

0 个答案:

没有答案