.length
comfirm("");
prompt(""); Use the prompt
command to ask the user where they are from.
number string boolean
console.log
===
Equal to!==
Not equal to
在Js中函数是没有重载,定义相同函数名、不同参数签名的函数,后面的函数会覆盖前面的函数。调用时,只会调用后面的函数。
As we mentioned, for
loops are great for doing the same task over and over when you know ahead of time how many times you'll have to repeat the loop. On the other hand, while
loops are ideal when you have to loop, but you don't know ahead of time how many times you'll need to loop.
6.3 浅度复制
说明:Array类型是一种引用类型;当数组a复制给数组b时,对数组b进行元素修改,数组a也会发生修改。
示例:
1
2
3
4
|
var demoArrayA = [ 'a' , 'b' , 'c' , 'd' , 'e' ]; var demoArrayB = demoArrayA; // 把数组A 赋值给数组B demoArrayB[0] = 1; // 对数组B 的元素进行修改 console.log(demoArrayA); // => [1, 'b', 'c', 'd', 'e']:数组A 的元素也发生了变更 |
6.4 深度复制
说明:使用concat()方法,返回新的数组;防止浅度复制的情况发生,对数组b进行元素修改操作,数组a不发生变更。
示例:
1
2
3
4
5
|
var demoArrayA = [ 'a' , 'b' , 'c' , 'd' , 'e' ]; var demoArrayB = demoArrayA.concat(); // 使用concat()方法,返回新的数组 demoArrayB[0] = 1; // 对数组B 的元素进行修改 console.log(demoArrayA); // => ['a', 'b', 'c', 'd', 'e']:数组A 的元素没变更 console.log(demoArrayB); // => [ 1, 'b', 'c', 'd', 'e']:数组B 的元素发生了变更 |