//
/*
*/
// 也可以单独指定在一个函数中进行 'use strict'
ECMAScript变量是松散类型的,变量可以用于保存任何类型数据,每个变量只不过是一个用于保存任意值的命名占位符
声明变量:
使用var声明的变量,声明语句会提升到作用域顶端
六种简单数据类型:
使用typeof操作符会返回以下字符串之一
Undefined类型只有一个值,就是undefined
声明了变量但是没有初始化就相当给变量赋值了undefined
null类型同样只有一个值,即特殊值null
从逻辑上讲,null表示一个空对象指针
在定义用来保存对象的变量时,建议使用null来初始化
有两个字面值,不同类型装Boolean的表格
字符串表示:
字符串的特点
function tagFunction(strings, aValExpr, bValExpr, sumValExpr) { console.log(strings); console.log(aValExpr); console.log(bValExpr); console.log(sumValExpr); return sumValExpr; } let a = 1, b = 2; let taggedResult = tagFunction `${a} + ${b} = ${a + b}`; console.log(taggedResult); /** * [ '', ' + ', ' = ', '' ] * 1 * 2 * 3 * 3 */
ES6新增
doing multiple operation in one sentence
let num = 1, num2 = 2, num3 = 3;
loop
a while sentence that test it after doing a loop
do { // statement } while (expression)
the 'for' sentence have initial code.
a strict iteration sentence, enumerated properties in an object
if the object that will be enumerated is null or undefinde, the loop sentence will not be executed.
for (property in expression) { // statement }
a strict iteration sentence, enumerated elements in an object
for (property of expression) { // statement }
The label sentence is using to add label to sentence.
// syntax label: statement; // example let count = 5; start: for (let i = 0; i < count; i += 1) { console.log(i); if (i === 2) continue start; }
The useness of 'with' is setting the code scope to a certain object
let obj = { age: 12, name: 'azoux', }; with(obj) { console.log(name); // azoux console.log(age); // 12 }
the strict mode would not allowed the use of 'with'.
switch(expression) { case value1: statement break; case value2: statement break; // case n default: break; }
the reason why we add 'break' sentence to all cases is to avoid unnecessory judgement.
The best practice is that a function either returns a value or does not return a value. Functions that return values only under certain conditions will bring
Trouble, especially when debugging.