【文件属性】:
文件名称:ist的matlab代码-js-gotchas:JavaScript陷阱和常见错误
文件大小:2KB
文件格式:ZIP
更新时间:2021-05-26 07:47:05
系统开源
ist的matlab代码js-gotchas
JavaScript陷阱和常见错误
1.
0是虚假的,但"0"是正确的。
if
(
0
)
{
console
.
log
(
'yey.'
)
;
}
else
{
console
.
log
(
'boom'
)
;
//
this
will
be
printed
}
if
(
"0"
)
{
console
.
log
(
'yey.'
)
;
//
this
will
be
printed
}
else
{
console
.
log
(
'boom'
)
;
}
为什么?
因为强迫。
Javascript看到一个字符串,并且像Java语言一样是一种等效语言,它会尝试自行修复。
现在,如果condition需要布尔输出,那么编译器将尝试将字符串转换为布尔运算符。
这就是toBoolean应该如何按照的7.1.2节进行工作的方式
如果参数为空String(长度为零),则结果为false;否则,结果为false。
否则结果为true。
因此,Empty字符串将返回false,其余的一切将返回true。
2.
MIN_VALUE和MAX_
【文件预览】:
js-gotchas-master
----README.md(4KB)