-
1 +new Date() --隱式轉(zhuǎn)換
JavaScript的隱式轉(zhuǎn)換,在使用“ + - | ~~ ”的時(shí)候會(huì)先轉(zhuǎn)換變量的類型再進(jìn)行計(jì)算
s= new Date().toString();
//"Thu Aug 03 2017 09:44:12 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)"
t= +new Date().toString();
//"1501724677368"
//s===t.getTime();
~~123.45
//123
~~-123.45
//-123
//相當(dāng)于 "~~"==parseInt(argument,10)
//當(dāng)然我們還可以用 “|”來取整
234.56 | 0
//234.56
-234.56 | 0
//-234
234.56 | undefined
//234.56
-234.56 | undefined
//-234
var str = "string";
var strObj = new String("string");
alert(str)
//"string"
alert(strObj)
//String0: "s"1: "t"2: "r"3: "i"4: "n"5: "g"length: 6__proto__: String[[PrimitiveValue]]: //"string"
alert(str.length)
//6
alert(str.t = 10)
//10
alert(str.t)
//undefined
-
3檢測(cè)類型
typeof
instanceOf
duck type
object.protype.toString([])
-
3 運(yùn)算符
" , "運(yùn)算符,運(yùn)算最右邊的值
三元運(yùn)算符 a?b:c
"new"
function Foo(){};
Foo.protoptype.x = 1;
var obj = new Foo();
obj.hasOwnProperty('x');//false
obj._proto_hasOwnProperty('x');//true