Javascript ++: How to Level Up Your Code

Try to Avoid Type Constructors

let x1 = new Object();
let x2 = new String();
let x3 = new Number();
let a1 = {};
let a2 = "";
let a3 = 0;

Use Strict Equals

"42" == 42
=> true

Abstract Comparators perform a type conversion when comparing so if you try to compare a string with a number, you might find yourself with a true value instead of a false one.

Strict Equality Comparison (===)

"42" === 42
=> false

Strict Comparators don’t do a type conversion so if the two objects you are comparing aren’t both integers (for example) with the same value, then you will get a false output since, well, these two objects aren’t the same thing!

Lots of Variables

function sayHello(options) {
let sentence = {
greeting: "Good morning!",
pleasantry: "How are you,",
name: "buddy",
exclamation: "?",
question: "some coffee?"
let name = "John"
let exclamation = "!?"
let question = "lunch?
function sayHello(, , name, question, exclamation)
=> "Good morning! How are you, John!? Do you want to grab lunch?"

Thoroughly Comment Your Code

//This code will greet a user upon loginfunction greeting() {

Passing Empty Parameters

method(...['parameter1', , 'parameter3'])


Full-Stack Engineer, UX/UI Aficionado, and lover of coffee.

Full-Stack Engineer, UX/UI Aficionado, and lover of coffee.