17 个高频好用的JavaScript 代码块( 二 )

反而
function rectangle(h =0,w=0){return h*w;}console.log(rectangle(1,12))13、Math.Floor 简写var val = "1212121212"console.log(Math.floor(val)) // Long oneconsole.log(~~val) // smart one14、toString 简写var someNumber = 123console.log(someNumber.toString()) //return "123"// Or in SHORT CUTconsole.log(`${someNumber}`) //return "123"15、For 循环for(let i=0;i<1e3;i++){ // instead of i<1000, Cool, right?}16、值到对象映射,即键和值相同var x='x',y='y'var obj = {x,y} // instead of {x:x, y:y}console.log(obj)17、多行字符串var multiLineString = `some stringnwith multi-line ofncharactersn`console.log(multiLineString)



推荐阅读