read speaking javascript
基本值有: booleans,numbers,strings,null and defined 其他所有值都是:objects
3 === 3 // true
'abc' === "abc" // true
Always immutable
)> var str = 'abc';
> str.length = 1; // try to change property `length`
> str.length // ⇒ no effect
3
> str.foo = 3; // try to create property `foo`
> str.foo // ⇒ no effect, unknown property
undefined
所有非基本值的都是对象,常见的对象有
{ firstName: 'Jane', lastName: 'Doe' }
[ 'apple', 'banana', 'cherry' ]
/^a+b+$/
> ({} === {}) // two different empty objects
false
> var obj1 = {};
> var obj2 = obj1;
> obj1 === obj2
true
> var obj = {};
> obj.foo = 123; // add property `foo`
> obj.foo
123
undefined
undefined
> var foo;
> foo
undefined
undefined
> function f(x) { return x }
> f()
undefined
undefined
> var obj = {}; // empty object
> obj.foo
undefined
null
null表示空对象。
undefined
和null
均没有属性
undefined and null have no properties, not even standard methods such as toString().
Booleans
布尔值有两个true、false
。下面的操作符可以生成布尔值
&& , ||
!
===, !==, ==, !=
>, >=, <, <=
下面几种值,表示false值
undefined,null
false
空数组