JavaScript - New

2018-10-01  本文已影响0人  ft207741

Menu


JavaScript有三种声明方式。

变量提升
函数提升

数据结构和类型

数据类型
//null
var foo = null; 
document.write(foo);  //null
//Symbol
let id1 = Symbol("id");
let id2 = Symbol("id");

alert(id1 == id2); // false
数据类型的转换
"37" - 7 // 30
"37" + 7 // "377"
x = (+"1.1") + (+"1.1") // 括号可以去掉
document.write(x); //2.2

字面量

数组字面量(python中的列表)
var list1 = ["a", , "b"];
document.write(list1[1]); //undefined 
var l = ["a", , "b",];
document.write(list1.length); // 3
var obj = {
  " ": "value1",
  "!": "value2"
}
  console.log(obj." "); // Unexpected string
  document.write(obj[""]); //value1
  console.log(obj.!); //Unexpected token !

请注意:

var foo = {a: "alpha", 2: "two"};
console.log(foo.a);    // alpha
console.log(foo[2]);   // two
//console.log(foo.2);  // SyntaxError: missing ) after argument list
//console.log(foo[a]); // ReferenceError: a is not defined
console.log(foo["a"]); // alpha
console.log(foo["2"]); // two
上一篇下一篇

猜你喜欢

热点阅读