Four Unsolicited Tips for New JavaScript Developers

Brandon Fonnemann
The Startup
Published in
4 min readNov 9, 2020

--

Consider ‘Strict’ Mode

'use strict';

Introduced in ES5, strict mode allows for writing secure JavaScript code. With a different set of semantics versus the normal default “sloppy” mode , deployment of strict mode can significantly help in mitigating accidental programmer errors that could potentially introduce bugs into your application. This is because it restricts certain types of activities as well as generate visible errors in certain situations that would otherwise fail silently in the background without alerting the developer.

'use strict';let hasBirthdayGift = false;
const birthday = true;

if (birthday) hasBirrthdayGift = true;
if (hasBirthdayGift) console.log('I have presents! :D')

Output: Uncaught ReferenceError: hasBirrthdayGift is not defined
**this error would normally fail silently in the background without alerting the developer if strict mode was commented out.

Strict mode and non-strict mode can coexist in beautiful harmony, so scripts can opt into strict mode incrementally.

let num = 1;  //validfunction sum(num1, num2) {
'use strict';
result = num1 + num2; // error

--

--

Brandon Fonnemann
The Startup

It’s hip to b[e= mc²] → 7.819 x 10¹⁸ Joules