tag
基础语法
1.注释
//不被编译注释
/*被编译的注释*/
2.语句
- 一条语句结束加分号;
- 驼峰命名 单词缩写
- {} 写js代码块/对象;
- var 用于声明变量
- let const 用于声明变量
3.js基本数据类型
数字 字符 布尔 数组 对象 函数 null undefined
Symbol
4.js运算符
- 算术运算符:+ - * / %
- 比较运算:==(等于) ===(恒等于) !=(不等于) !==(不恒等于)
- 比较运算:< > <= >=
- 字符串拼接符:+ ``
- 逻辑运算符:&& || !
- 赋值运算符:= += *= -= /=
typeof 运算符和数据类型
console.log(typeof 1);// number
console.log(typeof NaN) // number
console.log(typeof 'a'); // string
console.log(typeof false); // boolean
console.log(typeof []); // object typeof []/{}/null
console.log(typeof function(){}); // function typeof function(){} / Symbol
console.log(typeof undefined); // undefined
instanceof 运算符和对象数据类型
function Foo(){} // 构造函数
function Bar(){}
Bar.prototype = new Foo() // 原型对象 原型链
let obj = new Bar() // 实例
obj instanceof Bar //true
obj instanceof Foo //true
// 复杂判断
Number instanceof Number //false
String instanceof String //false
Object instanceof Object //true
Function instanceof Function //true
Function instanceof Object //true
5.转数字类型
undefined NaN
null 0
true 1
false 0
string 0/1/NaN
var a; // undefined
console.log( typeof Number(function(){return 1}()));// 其他数据类型转 number/NaN
console.log(Number({}));// NaN {} function 'a' undefined
console.log( Number(function(){return 1}()));// 1 true '1'
console.log( Number(function(){return ''}()));// 0 '' '0' null [] false
https://blog.csdn.net/LGHunter/article/details/82773730 String.valueOf(object)和object.toString()的区别