niomjobs.blogg.se

Ecmascript 6
Ecmascript 6












ecmascript 6 ecmascript 6

Optimizing small constant ranges for map() Context if the map returned it would cast from to "4" to 4 and make it 4|n array cast from to "," to NaN to 0 and 0|n = n, We all know that arrow functions save a lot of byts function A() in map ensures it returns an array of undefined, so the | will make the returned Since I joined this site a week back, I have learned a lot of useful tricks from fellow members. My primary programming language is JS and mostly ES6. Now p can be used for parseInt, saving you many bytes over the long run. If you are using this > 7 times, then it will be shorter to use parseInt and rename it: (p=parseInt)(v,2) You can adapt this your case for better results '0b'+v-0 // Shorter, but may not work in all cases +('0b'+v) // ES6 - 4 bytes saved use '0o' for octal and '0x' for hex You can use 0b, 0o, and 0x, for binary, octal, and hex respectively.: parseInt(v,2) // ES5 + can be used to convert a binary, octal or hex string to a decimal number.

ecmascript 6

z = ĮS6 provides a much shorter way to convert form Base-2 (binary) and Base-8 (octal) to decimal: 0b111110111 // = 503 You can also use this to shorten slice() functions. = // ES6 - not shorter, but more flexible You can even use this to reverse variables: c=a,a=b,b=c // ES5 - uses extra variable This can also be used like: a=r,b=r // ES5 Property shorthands allow you to set variables to an arrays' values: a=r b=r // ES5














Ecmascript 6