When action grows unprofitable, gather information; when information grows unprofitable, sleep.                                      Ursula K. Le Guin, The Left Hand of Darkness

索引

  1. 作者的几个观点

  2. ECMAScript standard

  3. Values, Types, and Operators
  4. Web browsers are not the only platforms on which JavaScript is used. Some databases, such as MongoDB and CouchDB, use JavaScript as their scripting and query language.

这个教程应该是在持续更新的,作者在 Introduction 中表示书中用的是 2017 版本的 JavaScript

COPY ↓

Keeping programs under control is the main problem of programming.

The art of programming is the skill of controlling complexity.

Some programmers believe that this complexity is best managed by using only a small set of well-understood techniques in their programs. They have composed strict rules (“best practices”) prescribing the form programs should have, and carefully stay within their safe little zone.

This is not only boring, it is also ineffective. New problems often require new solutions. The field of programming is young and still developing rapidly, and is varied enough to have room for wildly different approaches. There are many terrible mistakes to make in program design, and you should go ahead and make them so that you understand them. A sense of what a good program looks like is developed in practice, not learned from a list of rules.

Standard ECMA-262 - Ecma International

After its adoption outside of Netscape, a standard document was written to describe the way the JavaScript language should work, so that the various pieces of software that claimed to support JavaScript were actually talking about the same language. This is called theECMAScript standard, after the Ecma International organization that did the standardization.

Values, Types, and Operators

  1. Bits
  2. Values -

    每个值都必须存储在某个地方,如果您想同时使用大量数据,则可能会导致内存不足。幸运的是,只有在同时需要大量值的时候,这才是一个问题。只要你不再使用值,它就会消失,留下它的一部分 作为下一代值的建筑材料。

    本章介绍JavaScript程序的原子元素,即简单的值类型和可以处理这些值的操作符

  3. Numbers - JavaScript 用定长的比特存储数字 -- -JavaScript uses a fixed number of bits, namely 64 of them, to store a single number value. you can represent 264different numbers, which is about 18 quintillion (an 18 with 18 zeros after it). 仅仅是 2 的 64 次方个不同数字!并不是指如此多的正整数。  ---- - Not all whole numbers below 18 quintillion fit in a JavaScript number, though. Those bits also store negative numbers, so one bit indicates the sign of the number. A bigger issue is that nonwhole numbers must also be represented. To do this, some of the bits are used to store the position of the decimal point. The actual maximum whole number that can be stored is more in the range of 9 quadrillion (15 zeros)—which is still pleasantly huge.

  4. Special numbers -- The first two are Infinity and -Infinity, which represent the positive and negative infinities. Infinity - 1 is still Infinity, and so on. Don’t put too much trust in infinity-based computation, though. It isn’t mathematically sound, and it will quickly lead to our next special number: NaN.     --------------- NaN stands for “not a number”, even though it is a value of the number type. You’ll get this result when you, for example, try to calculate 0 / 0 (zero divided by zero), Infinity - Infinity, or any number of other numeric operations that don’t yield a meaningful result.

  5.  Strings, too, have to be modeled as a series of bits to be able to exist inside the computer. The way JavaScript does this is based on the Unicode standard. This standard assigns a number to virtually every character you would ever need, including characters from Greek, Arabic, Japanese, Armenian, and so on. If we have a number for every character, a string can be described by a sequence of numbers.  -- -'/n' -- - And that’s what JavaScript does. But there’s a complication: JavaScript’s representation uses 16 bits per string element, which can describe up to 216different characters. But Unicode defines more characters than that—about twice as many, at this point. So some characters, such as many emoji, take up two “character positions in JavaScript strings.
  6. Unary operators -- --Not all operators are symbols. Some are written as words. One example is the typeof operator, which produces a string value naming the type of the value you give it. 这里提到一个非符号一元操作符 typeof →  console.log(typeof 4.5) output = number

  7. Comparison - - -There is only one value in JavaScript that is not equal to itself, and that is NaN (“not a number”).  console.log(NaN == NaN) // → false   - -----  - NaN is supposed to denote the result of a nonsensical computation, and as such, it isn’t equal to the result of any other nonsensical computations.

  8. Empty values -- 别把它和 Special numbers  搞混了,它已经脱离了 数(numbers)的范畴了。

    有两个特殊值,写成 nullundefined,用来表示意义缺失的值(也就是没有意义的值)。 它们本身是值,但它们没有包含任何信息。

    语言中有许多没有得到有意义的值的操作(稍后会看到)会产生 undefined,因为它们必须产生一些值。↑ (虽然 没有包含任何信息)

    undefined 和 null 之间含义的差异 是 JavaScript设计的一个意外,大多数时候它并不重要。 在你不得不关注这些值的情况下,我建议将它们视为大体上可互换的。

Empty values # 摘

There are two special values, written null and undefined, that are used to denote the absence of a meaningful value. They are themselves values, but they carry no information.

Many operations in the language that don’t produce a meaningful value (you’ll see some later) yield undefined simply because they have to yield some value.

The difference in meaning between undefined and null is an accident of JavaScript’s design, and it doesn’t matter most of the time. In the cases where you actually have to concern yourself with these values, I recommend treating them as mostly interchangeable.

Automatic type conversion # 摘

When you do not want any automatic type conversions to happen, there are two additional operators: === and !==. The first tests whether a value is precisely equal to the other, and the second tests whether it is not precisely equal. So "" === false is false as expected.

/

I recommend using the three-character comparison operators defensively to prevent unexpected type conversions from tripping you up. But when you’re certain the types on both sides will be the same, there is no problem with using the shorter operators.

/

We can use this functionality as a way to fall back on a default value. If you have a value that might be empty, you can put || after it with a replacement value. If the initial value can be converted to false, you’ll get the replacement instead. 逻辑运算的奇淫巧技,就是说逻辑运算符号两侧如果不是布尔值,那么将会把左侧值自动转化为布尔值然后根据转化结果返回 两侧值中的一个。 那么谁知道左侧值会转化为 false 还是 true 呢? 规则是这样的:0,NaN,"" 都是false 其余都是 true,那为什么只转化一边就可以决定返回值呢?原因当然是因为短路运算啦。。。

NaN || "3333"
"3333" 0 || "3333"
"3333" "" || "3333"
"3333" Infinity || "3333"
Infinity null || "3333"
"3333" undefined || "3333"
"3333"

不过经过我测试 null 和 undefined 返回的也是 false 所以还是慎用。。。

/

Another important property of these two operators is that the part to their right is evaluated only when necessary. In the case of true || X, no matter what X is—even if it’s a piece of program that does something terrible—the result will be true, and X is never evaluated. The same goes for false && X, which is false and will ignore X. This is called short-circuit evaluation.

The conditional operator works in a similar way. Of the second and third value, only the one that is selected is evaluated.

Eloquent JavaScript #01# values的更多相关文章

  1. Eloquent JavaScript #13# HTTP and Forms

    索引 Notes fetch form focus Disabled fields form’s elements property 阻止提交 快速插入单词 实时统计字数 监听checkbox和rad ...

  2. Eloquent JavaScript #04# Objects and Arrays

    要点索引: JSON More ... 练习 1.补:js字符串的表达方式有三种: "" 和 '' 没什么区别,唯一区别在于 "" 中写 "要转义字符 ...

  3. 闲扯 Javascript 01 实现选项卡

    javascript 实现选项卡 今天下午的两节课,在机房闲来没事 ,就学习了javascript 怎么获取HTML的标签,改变CSS样式,资料来源 智能社! <script> windo ...

  4. 初识 Javascript.01 -- Javascript基础|输出方式、变量、变量命名规范、数据类型、

    Javascript基础 1 聊聊Javascript 1.1 Javascript的历史来源 94年网景公司   研发出世界上第一款浏览器. 95年 sun公司   java语言诞生 网景公司和su ...

  5. Eloquent JavaScript #11# The Document Object Model

    索引 Notes js与html DOM 在DOM树中移动 在DOM中寻找元素 改变Document 创建节点 html元素属性 布局 style CSS选择器 动画 Exercises Build ...

  6. Eloquent JavaScript #10# Modules

    索引 Notes 背景问题 模块Modules 软件包Packages 简易模块 Evaluating data as code CommonJS modules ECMAScript modules ...

  7. Eloquent JavaScript #09# Regular Expressions

    索引 Notes js创建正则表达式的两种方式 js正则匹配方式(1) 字符集合 重复匹配 分组(子表达式) js正则匹配方式(2) The Date class 匹配整个字符串 Choice pat ...

  8. Eloquent JavaScript #03# functions

    索引: let VS. var 定义函数的几种方式 more... 1.作者反复用的side effect side effect就是对世界造成的改变,例如说打印某些东西到屏幕,或者以某种方式改变机器 ...

  9. Eloquent JavaScript #02# program_structure

    第一章中作者介绍了各种值,但是这些独立的值是没有意义的,只有当值放在更大的框架的时候才会彰显它们的价值.所以第二章开始介绍程序结构. 1.var VS. let 以及 const 作者推荐用 let ...

随机推荐

  1. 如何创建线程第二种实现Runnable接口

    package TestException; public class test5 { public static void main(String[] args) { Test6 s1 = new ...

  2. iot-hub运行在虚拟上

    ng  build gradlew build java -jar iot-hub-0.0.1-SNAPSHOT.jar 后台运行  nohup java -jar iot-dm-0.0.1-SNAP ...

  3. 要求根据RandomStr.java:使用类型转换生成六位验证字符串,示例程序每次运 行时,都会生成不同的字符串。

    1.程序设计思想验证码 ①定义一个字符串变量来保存随机生成的. ②利用循环产生六位随机数,在产生每一位时将其转换为char类型并写在字符串后面. ③利用对话框显示生成的验证码,并提示用户输入验证码. ...

  4. numpy.meshgrid()

    numpy提供的numpy.meshgrid()函数可以让我们快速生成坐标矩阵X,Y 语法:X,Y = numpy.meshgrid(x, y)输入:x,y,就是网格点的横纵坐标列向量(非矩阵)输出: ...

  5. JAVA编程思想学习笔记7-chap19-21-斗之气7段

    1.枚举 2.内置三种注解 @Override @Deprecated @SuppressWarnings 3.元注解:用于注解其它注解 4.注解处理器:通过反射 5.创建线程的两种方式 实现Runn ...

  6. Oracle 10g使用amdu抽取数据文件

    环境:OEL 5.7 + Oracle 10.2.0.5 RAC 需求:实验在Oracle 10g环境使用amdu抽取数据库文件 本文主要目的是介绍3个知识点: 1.使amdu可以在oracle 10 ...

  7. 1.Spring对JDBC整合支持

    1.Spring对JDBC整合支持 Spring对DAO提供哪些支持 1)Spring对DAO异常提供统一处理 2)Spring对DAO编写提供支持的抽象类 3)提高编程效率,减少DAO编码量 Spr ...

  8. node.js连接本地数据库及json返回数据

    新建一个文件夹node.js,目录下打开命令初始化一下 cnpm init 然后下载express框架 cnpm install express --save 接着下载数据库的依赖 cnpm inst ...

  9. Hadoop.之.入门部署

    一.课程目标 ->大数据是什么?大数据能做什么? ->什么是Hadoop?Hadoop的设计思想? ->Hadoop如何解决大数据的问题?(什么是hdfs与yarn.MapReduc ...

  10. Linux 切换用户

    Linux用户之间切换 在linux操作系统中,用户之间的切换使用,su 命令.linux系统环境中的用户信息如下: 用户名 角色 备注 root 管理员 root用户下配置的jdk 版本为:1.8 ...