javascript variable's weird behaviour
javascript variable's weird behaviour
情况1 -如果在变量声明之前使用console.log(variable),则未定义。例如,
// code
console.log(a);
var a ;
// output
undefined
情况2 -如果我console.log(变量)没有变量声明,我得到Uncaught ReferenceError:变量未定义。
// code
console.log(a);
// output
Uncaught ReferenceError: a is not defined
但是对于函数,我们可以在函数定义之前或之后调用函数,这不会产生任何问题。例如,
console.log(example());
function example(){
return 'test done';
}
console.log(example());
// output without any issue
现在我的问题是,未定义和未定义有什么区别?
Undefined表示变量存在,但没有任何存储值。
相关文章:
- Strange Behaviour java variable
- Jquery append html weird behavior
- Behaviour of withCredentials flag of XMLHttpRequest lvl 2 in
- nodejs and javascript useragent behaviour
- Weird Javascript Array.prototype.constructor.apply behaviour
- Javascript strage scope behaviour
- Weird behavior in chrome's javascript .width property
- Javascript: wierd RegExp behaviour
- 从函数WEIRD RESULTS调用函数
- ajaxt weird error: Uncaught SyntaxError: Unexpected token if
- javascript:void(0) and target="_blank" behaviour
- Weird bug with Accounts.onCreatedUser
- Javascript's Map() function's weird behaviour
- Equivalent behaviour of 'jQuery.active' in q
- Weird usage of && outside of a if?
- jQuery.getScript() behaviour
- CSS Behaviour for IE: first-of-type
- javascript variable's weird behaviour
- Javascript weird parseFloat
- weird Date()解析错误