var say1 = 'I\'m is ...'; 输出:“I'm is ...”
var say2 = "\"Tom\""; 输出:“Tom”
就是把要输出的符号前面加上\就行了
var num1 = 12,num2 = '34' ,sum = 0;
console.log(typeof num1); //输出结果:number
console.log(typeof num2); //输出结果:string
console.log(typeof sum); //输出结果:string
console.log(typeof null); //输出结果:object,而不是null
var data = null;
var type = 'Null';
Object.prototype.toString.call(data) == '[object'+type+']';
var num1 = prompt('数1') //输入:123abc
var num2 = prompt(‘数2’) //输入:456
console.log(num1+num2); //结果:123abc456
console.log(parseInt(num1)+parseInt(num2)); //结果:579
待转数据 | Number() | parseInt() | parseFloat() |
---|---|---|---|
纯数字字符串 | 转成对应的数字 | 转成对应的数字 | 转成对应的数字 |
空字符串 | 0 | NaN | NaN |
数字开头的字符串 | NaN | 转成数字开头的数字 | 转成数字开头的数字 |
非数字开头字符串 | NaN | NaN | NaN |
null | 0 | NaN | NaN |
undefined | NaN | NaN | NaN |
false | 0 | NaN | NaN |
true | 1 | NaN | NaN |
console.log(parseInt('123abc')); //结果:123
console.log(parseInt('F',16); //结果:15 后面的参数表示16进账表示