Due to indexes are not even defined for empty element, in operator return false.
var arr = new Array(5);
console.log(1 in arr); // false
arr[1] = undefined;| .item { | |
| margin-bottom: 20px; | |
| padding: 10px; | |
| font-size: 0; | |
| border: 1px solid #efefef; | |
| } | |
| .item .pic , | |
| .item .content { | |
| display: table-cell; | |
| *display: inline; |
var foo = 'foo';
console.log(this.foo); // 'foo'In global execution context, declaring a variable means add a property to this
(function () {
var bar = 'bar';
console.log(this.bar); // undefinedvar objInGlobal = {
a: 'a',
b: 'b'
};
(function (baseTypeVar, referTypeVar, notPassedArg) {
baseTypeVar = 2;
console.log(baseTypeVar === arguments[0]); // true
Array in JavaScript is actually object:
length property.Array which provides some methods to be inherited, e.g. forEach.Array in C is different, it always uses sequence memory, at this point, it is real array.
So what it means?
| // example 1 | |
| (function () { | |
| console.log(typeof func); // 'function' | |
| function func () {} | |
| console.log(typeof func); // 'function' | |
| })(); | |
| // example 2 | |
| (function () { |
example 1
var sum = 0.1 + 0.2; // 0.30000000000000004
// way 1:
Number(sum.toFixed(5)) === 0.3; // true
// way 2:
(sum - 0.3) < 1e-5; // true| var i, arr = ["dwdwad","dwdawd","dwdwad","ddd","sss"], target = 'ddd'; | |
| var hash = {}; | |
| for(i = 0; i < arr.length; ++i) { | |
| hash[arr[i]] = i; | |
| } | |
| console.log(hash[target]); |
| // Why? | |
| // too long? How long is too long? | |
| Math.ceil(3.0000000000000001); // 3 | |
| Math.ceil(3.000000000000001); // 4 |
REST: Representational state transfer 表征状态转移
表示各个HTTP请求之间是无状态的,也就是说单个HTTP请求包含了所作操作需要的所有信息。请求会使资源的状态发生变化(GET除外,但如果产生访问记录也算状态变化的话,那么GET也算)。