在javascript中声明变量时,默认值是null吗? [英] When declaring a variable in javascript, is the default value null?

查看:96
本文介绍了在javascript中声明变量时,默认值是null吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有如下声明:

var j;

j == null 直到我设置它等于什么?

does j==null until I set it equal to something?

推荐答案

不,它的默认值为 undefined

但是如果想要使用!j 条件,它将适用于这两个值(即未定义 null

No, it has the default value of undefined
But if want to use the !j condition, it will work with both the values (i.e. undefined or null)

请注意(j == null) true ,但(j === null) false ... JavaScript有虚假值,有时会有意外的规则来转换值,加上花哨的 === 运算符来比较值并同时输入。

Note that (j==null) is true, but (j===null) is false... JavaScript have "falsy" values and sometimes unexpected rules to convert values, plus fancy === operator to compare value and type at the same time.

这篇关于在javascript中声明变量时,默认值是null吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆