转换
console.log(!!' ' + !!'');
console.log(typeof typeof 123)
console.log(typeof undefined === 'undefined')
console.log(!![] == [])
console.log(!!{} == {})
console.log('4.5' < '11') //两个字符串比较ascll码 //console.log('4.5'<11)
console.log(NaN == NaN)
console.log(parseInt(true));
console.log(parseInt(false));
console.log(parseInt(null));
console.log(parseInt(undefined));
console.log(parseInt(NaN));
console.log(parseInt('3.54'));
console.log(parseInt(3.54));
console.log(parseInt('2', 2));
console.log(parseInt(a, 16));
console.log(parseInt('a', 16));
let a = undefined
// let a = null
console.log(a.toString());
let b = '123'
b++
console.log(b);
let c = undefined == 0
console.log(c);
let d = null == 0
console.log(d);
let e = null == undefined
console.log(e);
let f = null === undefined
console.log(f);
console.log(typeof (+'123'));
console.log(isNaN(null));
console.log(isNaN(undefined));
switch实现if
const i = 3;
switch (true) {
case (i <= 0): //括号可取消
console.log("small");
break;
case (i > 0 && i <= 10):
console.log("middle");
break;
default:
console.log("really big");
}
for 实现while
var i = 1;
for (; i;) {
console.log(i);
i++
if (i == 10) {
// i = 0
break;
}
}
// 打印0-100的数
//()只能有一句,不能比较
//{}不能出现i++ i-- i=i-1 i=i+1 ,不能变量更新等
var i = 101
for (; i--;) {
console.log(i);
}
关于函数的arguments
let fn = function fn1() {
console.log(1);
fn1()
return
}
// fn()
fn1()
/* ********************** */
function fn(a, j) {
fn.length
a = 3
console.log(arguments[0]);
}
fn(1, 2)
fn.length
/* ********************** */
function fn(a, j) {
j = 3
console.log(arguments[1]);
}
fn(1)
关于函数默认值
function fn(x, y) {
var x = (typeof arguments[0]) == 'undefined' ? 1 : arguments[0]
var y = (typeof arguments[1]) == 'undefined' ? 1 : arguments[1]
console.log(x + y);
}
fn(0, 0)