Last active
August 29, 2015 13:57
-
-
Save crazygit/9643934 to your computer and use it in GitHub Desktop.
javascript学习笔记
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
// javascrpt布尔值的类型转换 | |
console.log(Boolean(NaN)); // flase | |
console.log(Boolean(null)); // false | |
console.log(Boolean(undefined)); // false | |
console.log(Boolean(0)); // false | |
console.log(Boolean([])); // true 注意这里与python不同 | |
console.log(Boolean({})); // true 注意这里与python不同 |
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
// javascript的作用域 | |
// javascript是函数作用域:变量在声明它们的函数体以及这个函数体嵌套的任意函数体类都是有定义的 | |
function foo() | |
{ | |
for (var i=0; i< 10; i++) | |
{ | |
console.log(i); | |
} | |
console.log(i); // i=10 | |
} | |
foo() | |
// javascript函数内的变量声明都被提前到了函数体的顶部,函数体内的变量会覆盖全局变量 | |
var a="hello"; | |
function bar() | |
{ | |
console.log(a); //a="undefined", 这里覆盖了全局变量a="hello" | |
var a="world"; | |
console.log(a); // a="world" | |
} | |
bar() |
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
//in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望它的右操作数是一个对象。 | |
//如果右侧的对象拥有一个名为左操作数值的属性名,那么表达式返回true。 | |
var data=[7,8,9]; | |
console.log("0" in data); // true | |
console.log(1 in data); // true | |
console.log(3 in data); // false | |
console.log(7 in data); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment