1.js数据以及变量
//var 和 let的区别:var可以先 使用后定义,let必须先定义。
var n1 = 10;
var n2 = 20;
var temp = null;
let array = [1,2,3,4,5];
let age = 22;
let number = 3.1415926;
let a = prompt(
'请输入年龄'
);
document.write('我的年龄是:' + a);
let m; //只申明不给值 默认是 undefined
console.log(m);
let n = null; //空值,null其实是个对象
console.log(n);
console.log('-------------------------');
// typeof 检测数据类型
console.log(typeof 123); //number
console.log(typeof '你好'); //string
console.log(typeof false); //boolean
console.log(typeof pop); //undefined
console.log(typeof n); //object
let num = 10;
console.log(typeof num + '11'); //number11
//字符串转数字
console.log(Number.parseFloat('123.333')); //123.333
console.log(Number('12')); //12
console.log(parseInt('12.99999')); //12
console.log(Number('12.abc')); //NaN not a number
console.log(parseFloat('12.2abc')); // 12.2 必须是数字开头
console.log(+'100'); //number类型的 100,隐式转换
console.log('10' + 10); // 1010 字符串
console.log(1 * '1'); // number 的 1
console.log('1' / 1); //number 的1
console.log('1'-1);//number 的0
//数字转字符串
console.log(String(num)); //'10',字符串类型
console.log(num.toString()); //'10',字符串类型
console.log(num.toString(2)); // 1010 ,10的二进制