The Tips about Javascript That Virtually No One Knows About

The Tips about Javascript That Virtually No One Knows About

shubhu

Type of NaN is “number”

1
2
> typeof NaN
> "number"

You can modify the ‘console’ object

1
2
3
4
5
6
7
8
9
console._log = console.log;
console.log = function () {
console._log('logging...');
console._log.apply(null, arguments);
}

>console.log('test');
logging...
test

You can use unicode strings and egyptian hieroglyphs as variable names

1
2
let 𓀐𓅵𓀵𓁸𓃦 = "𓃂𓉤𓆣";
var ಠ_ಠ = function(){ console.log("Hello there"); }

Performance Tracking of functions

Use Performance.now() which is more accurate than console.time and console.timeEnd

1
2
3
4
start = performance.now();
foo();
stop = performance.now();
console.log("foo took " + (stop - start) + " milliseconds");

Object destructuring in ES6

1
2
3
4
5
// old
var username = req.body.username;
var password = req.body.password;
// ES6
var { username, password } = req.body;

Number Type coercion

1
2
3
4
> parseInt("5") + 2
7
> +"5" + 2
7

Find more on /r/ProgrammerTIL