The effect of console.log() is output, which actually means printing
comment // comment a line
/*balabala*/ Comment a paragraph
Add a semicolon on the same line to separate multiple statements
Simple data type: undefined, (empty variable) (cannot be used as a variable name)
null, (empty object) (cannot be used as a variable name)
boolean,
number,
srting
Complex data type: object object{a:s,a:s,a:s}
Several sets [a, a, a]
Brackets precedence from inside to outside
var a=3.1415926; a = a.toFixed(2);//Retain 2 bits but the result is a String type and cannot be calculated a = parseFloat(a);//Convert the result to float //Use one step as follows a = parseFloat(a.toFixed(2));
output after converting the object to an array
var info={a:1,b:2} info.a='1' info.b = '2' var new = JSON.stringify(info) console.log(new)
The property name of the object can be an identifier, a string, a value
The property value can be any data value, object, function
name = stu['name']
Can be used for dynamic value, variable (array name [i]) or string can be added in [ ]
The property name I want to access can be passed through a variable
[var stu = {name:1,age:2} (key-value ratio)
。。。
。。。
var sch = {name:1,age:2}
function get_value(data,value){
return data[value]
}
get_value(sch,name)】
Dynamically pass the property key value in the object (convenient to obtain the value when the variable name is reasonably defined)
[If the passed attribute value is a function, the output content will not execute the function]
condition ? expre1 : [align=center][/align]expre2;
true ->1
false->2
[prompt: popup window]
+=i is equal to (self plus i)
-=
*=
/=
%=
for loop
循环内的变量可以不加定义,但是循环内的变量不加定义则作用域变为全局,会被上下文修改
if 判断
&&与
||或
!非
数组 数组名[]
数组赋值push
var arr=[];
arr.push('字符串',team);把字符串和team代表的值加入数组中
若push数组A中的某元素进入数组B之后,不会改变数组A
空字符串 字符串名字=''
*.length 只能用于表示数组长度
【var a=Object.keys(对象名) 打印时输出对象的所有属性名
a.length 打印时输出对象长度】
函数返回值,调用函数内的运行结果,同时结束函数、循环 return表示结束;
不加返回值时,函数内的console.log在调用函数后正常执行;
返回多个值时需要把多个值组合成数组【或者对象?】
函数名(参数列表){代码块}
父级作用域不能访问子级作用域内的变量;子级作用域可以访问父级作用域的变量
但js中for(){} ;if(){}后的{}不看做块级作用域
在判断区域【如if后面的小括号里】内,判断something是否存在,可以在定义前进行分流如
var inputs = ['ITEM000001','ITEM000001','ITEM000001','ITEM000001','ITEM000001',] var info = {} inputs.forEach(function(value){ if(info[value]){ info[value]++ }else{ info[value] = 1 } })
所谓可以访问即是读取或修改
子作用域覆盖(子作用域有变量与父作用域变量重名时,子作用域里只能访问子作用域的变量)
var x = 0; function fun(){ console.log(x); var x = 1; x++; return x } fun();
先执行输出但父级变量已被覆盖,只不过被盖住还不知道是什么,因此输出为undefined,之后揭晓x的值与运算,代码执行的先后顺序(由上而下,由左至右)
A in B(对象名)
in 操作符用以确认 A 是否是 B 内的属性名
JavaScript 使用下列规则将非布尔值转换为布尔值:
1.所有对象都被视为 true。
2.当且仅当字符串为空时才被视为 false。
3.null 和未定义被认为是 false。
4.当且仅当数字为 0 时才为 false。