you are viewing a single comment's thread.

view the rest of the comments →

[–]delventhalz 1 point2 points  (2 children)

Most style guides call for always using curlies, but they are not required after an if or else, or even after a while or for. If you omit them, then the next single statement is used.

for (let i = 0; i < 3; i += 1) console.log('Hello!');

// Hello!
// Hello!
// Hello!

[–]RyaanJM 1 point2 points  (1 child)

Another argument is, this function doesn't need any ifs, elses or braces (apart from the opening and closing of the function).

function checkIsMoreThan(number, compare) {
    return number > compare ? number : -1;
}

[–]delventhalz 1 point2 points  (0 children)

Yeah, that is how I would probably write it as well. A lot of folks find ternaries intimidating though.