获得徽章 7
- 调JS代码的意外收获:undefined < 10是true吗?
false
因为undefined隐式类型转换之后是NaN
NaN不管大于小于等于任何数都是false展开93 - 前端扫盲系列:
juejin.cn
你不知道的动态脚本 —— 以下两段代码有什么区别?为什么?
<!DOCTYPE html>
<html lang="en">
<body>
<script>
document.body.innerHTML = "\<script\>function test() { alert('你在弄啥嘞??') };\<\/script>"
test()
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<body>
<script>
const script = document.createElement('script')
const content = document.createTextNode('function test() { alert("瞅啥??") }')
script.appendChild(content)
document.body.appendChild(script)
test()
</script>
</body>
</html>展开113