前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >《eloquent javascript》 notes1

《eloquent javascript》 notes1

作者头像
用户2936342
发布于 2018-08-27 06:49:13
发布于 2018-08-27 06:49:13
30200
代码可运行
举报
文章被收录于专栏:nummynummy
运行总次数:0
代码可运行
value, types and operator

There is only one value in JavaScript that is not equal to itself, and that is NaN, which stands for “not a number”.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
console.log(NaN == NaN)
// → false

When something that doesn’t map to a number in an obvious way (such as "five" or undefined) is converted to a number, the value NaN is produced. Further arithmetic operations on NaN keep producing NaN.

When comparing values of the same type using ==, the outcome is easy to predict: you should get true when both values are the same, except in the case of NaN.But when the types differ, JavaScript uses a complicated and confusing set of rules to determine what to do. In most cases, it just tries to convert one of the values to the other value’s type. However, when null or undefined occurs on either side of the operator, it produces true only if both sides are one of null or undefined.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
console.log(null == undefined);
// → true
console.log(null == 0);
// → false

That last piece of behavior is often useful. When you want to test whether a value has a real value instead of null or undefined, you can simply compare it to null with the == (or !=) operator.

The rules for converting strings and numbers to Boolean values state that 0, NaN, and the empty string ("") count as false, while all the other values count as true. Because of this, expressions like 0 == false and "" == false are also true.

data strcuture

Almost all JavaScript values have properties. The exceptions are null and undefined. If you try to access a property on one of these nonvalues, you get an error.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
null.length;
// → TypeError: Cannot read property 'length' of null
the document object

Unlike methods such as getElementsByTagName, the object returned by querySelectorAll is not live. It won’t change when you change the document.

The querySelector method (without the All part) works in a similar way. This one is useful if you want a specific, single element. It will return only the first matching element or null if no elements match.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017.08.08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
TypeScript 3.7 RC 发布,备受瞩目的 Optional Chaining 来了
We’re pleased to announce TypeScript 3.7 RC, the release candidate of TypeScript 3.7. Between now and the final release, we expect no further changes except for critical bug fixes.
苏南
2020/12/16
1.1K0
TypeScript 3.7 RC 发布,备受瞩目的 Optional Chaining 来了
Source Code Reading for Vue 3: How does `hasChanged` work?
Hey, guys! The next generation of Vue has released already. There are not only the brand new composition API, much more powerful and flexible reactivity system, first-class render function, but also the natural performance with building off the modern browsers.
^_^肥仔John
2021/11/11
4070
【自动化测试】【Jest-Selenium】(02)—— Jest 匹配器
Use .toBe to compare primitive values or to check referential identity of object instances. It calls Object.is to compare values, which is even better for testing than === strict equality operator.
WEBJ2EE
2020/10/09
8260
JavaScript之JS的数据类型
JavaScript一共有6中数据类型: 基本数据类型(5):字符串(String)、数字(Number)、布尔(Boolean)、数组(Array)、空(Null)、未定义(Undefined) 复杂数据类型(1):对象(Object) 注意:Array、Date、Math、Error Set(ES6).....都是属于Object中
用户1195962
2018/09/13
1.4K0
JavaScript之JS的数据类型
来一片成长快乐 —— JS Hacks 30+
童年回忆:小时候有个很出名的广告:“好高兴哦,又可以吃成长快乐了,我最爱吃成长快乐了~~”
掘金安东尼
2022/09/19
3700
来一片成长快乐 —— JS Hacks 30+
Javascript数组方法(ES5-ES6)
join(speparator):将数组的元素组起一个字符串,spearator为分隔符,省略的话则用默认用逗号为分隔符,该方法只接收一个参数,即分隔符。
用户9298250
2021/12/29
1.1K0
JavaScript ES6 — 少即是多,以少胜多,四两拨千斤
JavaScript ES6 brings new syntax and new awesome features to make your code more modern and more readable. It allows you to write less code and do more. ES6 introduces us to many great features like arrow functions, template strings, class destruction, Modules… and more. Let’s take a look.
一个会写诗的程序员
2018/12/06
4160
JavaScript ES6 — 少即是多,以少胜多,四两拨千斤
炫技!JavaScript 的花式玩法
JavaScript 是一个伟大的语言。它有简单的语法,完善的生态系统,更重要的,有一个庞大的社区。
疯狂的技术宅
2019/03/28
1.5K0
炫技!JavaScript 的花式玩法
44 个 JavaScript 变态题解析
当初笔者做这套题的时候不仅怀疑智商, 连人生都开始怀疑了…. 不过, 对于基础知识的理解是深入编程的前提. 让我们一起来看看这些变态题到底变态不变态吧! 第1题 ["1", "2", "3"].map(parseInt) 知识点: Array/map Number/parseInt JavaScript parseInt 首先, map接受两个参数, 一个回调函数 callback, 一个回调函数的this值 其中回调函数接受三个参数 currentValue, index, arrary; 而题目中, m
用户1667431
2018/04/18
9610
TS STRUCTURE - Basic TS Types
A variable with the number data type can contain anynumeric literal with float-ing, hexadecimal, and binary or octal values.
Cellinlab
2023/05/17
4440
JavaScript 新手的踩坑日记
在1995年5月,Eich 大神在10天内就写出了第一个脚本语言的版本,JavaScript 的第一个代号是 Mocha,Marc Andreesen 起的这个名字。由于商标问题以及很多产品已经使用了 Live 的前缀,网景市场部将它改名为 LiveScript。在1995年11月底,Navigator 2.0B3 发行,其中包含了该语言的原型,这个版本相比之前没有什么大的变化。在1995年12月初,Java 语言发展壮大,Sun 把 Java 的商标授权给了网景。这个语言被再次改名,变成了最终的名字——JavaScript。在之后的1997年1月,标准化以后,就成为现在的 ECMAScript。
一缕殇流化隐半边冰霜
2024/01/26
1360
JavaScript 新手的踩坑日记
系统刷JavaScripit 构建前端体系(语法篇)
现在更新文章频率降低了,公司项目活紧,充电时间比较紧了,每天只好抽取晚上的几个小时来学习补充了。
程序员海军
2021/09/15
3030
系统刷JavaScripit 构建前端体系(语法篇)
你不知道的javaScript笔记(4)
类型: JavaScript 有7种内置类型 空值 (null) 未定义(undefined) 布尔值(boolean) 数字(number) 字符串(string) 对象(object) 符号(symbol) 除对象以外,其他统称为“基本类型” 用typeof 运算符来查看值的类型 typeof undefined  === "undefined";   // true typeof true === "boolean";  // true typeof 42 === "number";  // tru
用户1197315
2018/01/22
6440
TypeScript中的怪语法
TypeScript中的怪语法 如何处理undefined 和 null undefined的含义是:一个变量没有初始化。 null的含义是:一个变量的值是空。 undefined 和 null 的最佳实践 核心思想: 避免null pointer错误。 null is bad。 要避免这个问题,我们需要做到: 用undefined,不要用null。 根据Code guidelines from Microsoft。 Enable "strict" 或者 "strictNullChecks" 编译选项
绿巨人
2018/05/16
4.4K0
JavaScript 新手的踩坑日记
在1995年5月,Eich 大神在10天内就写出了第一个脚本语言的版本,JavaScript 的第一个代号是 Mocha,Marc Andreesen 起的这个名字。由于商标问题以及很多产品已经使用了 Live 的前缀,网景市场部将它改名为 LiveScript。在1995年11月底,Navigator 2.0B3 发行,其中包含了该语言的原型,这个版本相比之前没有什么大的变化。在1995年12月初,Java 语言发展壮大,Sun 把 Java 的商标授权给了网景。这个语言被再次改名,变成了最终的名字——JavaScript。在之后的1997年1月,标准化以后,就成为现在的 ECMAScript。
一缕殇流化隐半边冰霜
2018/08/29
6000
JavaScript 新手的踩坑日记
JavaScript笔记(2)
使用表单,prompt获取过来的数据默认是字符串类型的,此时就不能直接简单的进行加法运算,而需要转换变量的数据类型.通俗来说,就是把一种数据类型的变量转换成另外一种的数据类型
y191024
2022/09/20
5760
JavaScript笔记(2)
从零开始学 Web 之 JavaScript(二)变量
基础数据类型: String,Number,Boolean,unsigned、null
Daotin
2018/08/31
5830
JavaScript 进阶问题列表[每日前端夜话0x95]
来源:https://github.com/lydiahallie/javascript-questions
疯狂的技术宅
2019/07/17
1.3K0
JavaScript 进阶问题列表[每日前端夜话0x95]
6个提升程序员幸福感的 JavaScript 小技巧
本文主要介绍一些JS中用到的小技巧,可以在日常Coding中提升幸福度,将不定期更新~
用户4962466
2019/10/17
5460
送你58道JavaScript面试题(上)
之前翻译过前阵子 github很火的 javascript-questions:送你43道JavaScript面试题
ConardLi
2019/08/21
7810
送你58道JavaScript面试题(上)
相关推荐
TypeScript 3.7 RC 发布,备受瞩目的 Optional Chaining 来了
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验