Created
January 18, 2014 08:51
-
-
Save wlyecn/8487914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 单行 | |
var name="Gates", age=56, job="CEO"; | |
/* 多行 | |
var name="Gates", | |
age=56, | |
job="CEO"; | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test(){ | |
message = "hi"; // 不加 var,message 成为全局变量 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
null == undefined; // true | |
"NaN" == NaN; // false | |
NaN == NaN; // false | |
"5" == 5; // true | |
"5" === 5; // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sayHi () { | |
// arguments 参数数组 | |
alert("Hello " + arguments[0] + "," + arguments[1]); | |
} | |
sayHi("Nicholas", "how are you today?"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doAdd(num1, num2) { | |
if(arguments.length == 1) { | |
alert(num1 + 10); | |
} else if (arguments.length == 2){ | |
alert(arguments[0] + num2); | |
} | |
} | |
doAdd(10); // 20 | |
doAdd(30, 20); // 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x; // x 为 undefined | |
var x = 6; // x 为数字 | |
var x = "Bill"; // x 为字符串 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var intNum = 55; // 整数 | |
var octalNum1 = 070; // 八进制的 56 | |
var octalNum2 = 079; // 无效的八进制数值 -- 解析为79 | |
var 0ctalNum3 = 08; // 无效的八进制数值 -- 解析为 8 | |
var hexNum1 = 0xA; // 十六进制的 10 | |
var hexNum2 = 0x1f; // 十六进制的 31 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var num1 = parseInt("1234blue"); // 1234 | |
var num2 = parseInt(""); // NaN | |
var num3 = parseInt("0xA"); // 10(十六进制数) | |
var num4 = parseInt(22.5); // 22 | |
var num5 = parseInt("070"); // 56(八进制数) | |
var num6 = parseInt("70"); // 70(十进制数) | |
var num7 = parseInt("0xf"); // 15(十六进制数) | |
var num7 = parseInt("f", 16); // 15(十六进制数) | |
var num1 = parseFloat("1234blue"); // 1234 (整数) | |
var num2 = parseFloat("0xA"); // 0 | |
var num3 = parseFloat("22.5"); // 22.5 | |
var num4 = parseFloat("22.34.5"); // 22.34 | |
var num5 = parseFloat("0908.5"); // 908.5 | |
var num6 = parseFloat("3.125e7"); // 31250000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lang = "Java"; | |
lang = lang + "Script"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 定义一个对象 | |
var person={firstname:"Bill", lastname:"Gates", id:5566}; | |
// 两种寻址方式 | |
name=person.lastname; | |
name=person["lastname"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ar s1 = "2"; | |
var s2 = "z"; | |
var b = false; | |
var f= 1.1; | |
var o = { | |
valueOf: function(){ | |
return -1; | |
} | |
}; | |
s1++; // 值变成数值3 | |
s2++; // 值变成 NaN | |
b++; // 值变成数值1 | |
f--; // 值变成 0.100000000000000000000009 (由于浮点舍入错误所致) | |
o--; // 值变成数值 -2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myObject = preferredObject || backupObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 所有大写字母编码值都小于小写字母 | |
var result = "Brick" < "alphabet" ; // true | |
// 2 的编码值小于 3 | |
var result = "23" < "3" ; // true | |
// "23"会被转换成 23 | |
var result = "23" < 3; // false | |
// "a"会被转换成 NaN | |
var result = "a" < 3 ; // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment