下面的例子中
var message;
alert(message); //”undefined”
alert(age); //causes an error
但是如果用typeof来看的话,那么:
两个都是'undefined',alert和typeof差异怎么这么大?
var message;
alert(message); //”undefined”
alert(age); //causes an error
但是如果用typeof来看的话,那么:
两个都是'undefined',alert和typeof差异怎么这么大?
解决方案 »
- 关于jquery dialog 浮动的问题
- 实在菜鸟,忘记了,怎样在表单中加入js 的处理啊,给个例子
- 【雷人现象】虚拟机的IIS环境中JS文件已更新,结果却总是老版本
- 关于vml问题。请帮忙
- 我想学习js编辑器的做法,源码,好长时间没找到,谁知道做法的说下(最好提代源码)先谢了。
- 我是菜鸟,专门注册个账号问高手一个html转JS代码的问题。
- 怎么动态改变OpenModalDialog弹出的对话框尺寸??
- microsoft.xmlhttp和msXml2.xmlhttp有什么区别?
- 如何让select中的某几项不能被选择?
- 这句话的问题?急用大虾看看好吗!
- 求助:jQuery关于checkbox里的checked全选/反选的问题
- javascript鼠标滑过下拉菜单位置确定问题
alert(TestVar); //shows undefined
alert(typeof TestVar); //shows undefinedvar TestVar = null;
alert(TestVar); //shows null
alert(typeof TestVar); //shows object
JavaScript: name? What's a name? I don't know what you're talking about. You haven't ever mentioned any name before. Are you seeing some other scripting language on the (client-)side?name = null;
You: What is name?
JavaScript: I don't know.
In short; undefined is where no notion of the thing exists; it has no type, and it's never been referenced before in that scope; null is where the thing is known to exist, but it's not known what the value is.
One thing to remember is that null is not, conceptually, the same as false or "" or such, even if they equate after type casting, i.e.name = false;
You: What is name?
JavaScript: Boolean false.name = '';
You: What is name?
JavaScript: Empty string
http://stackoverflow.com/questions/801032/why-is-null-an-object-and-whats-the-difference-compared-to-undefined
null表示说给你点东西,但你手里还是没东西
undefined:未定义,或者未初始化
alert(message); //获取变量的值 ”undefined”
alert(age); //获取变量的值 age 未定义,报错 causes an error
但是如果用typeof来看的话,那么:
两个都是'undefined',alert和typeof差异怎么这么大?typeof // 获取变量的 数据类型
undefine 没有注册