PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Backtick quotes

Allow to split the string into multiple lines.
 
let str = `
    ECMA International's TC39 is a group of JavaScript developers,
    implementers, academics, and more, collaborating ...
`;

Code first

When reading code, we first want to know what it does. If the code goes first, then it becomes clear from the start.
 
let elem = createElement();
setHandler(elem);

// --- helper functions ---
function createElement() { ... }
function setHandler(elem) { ... }

Comments as overview

Novices tend to use comments to explain “what is going on in the code”. But in good code, the amount of such “explanatory” comments should be minimal. Good comments provide a high-level overview of components. How they interact, what’s the control flow in various situations. In short – the bird’s eye view of the code. There’s a special language UML to build high-level architecture diagrams. Good comments allow us to understand the purpose of the function, without its code. Bad example:
 
// This code will do this thing (...) and that thing (...)
// ...and who knows what else...
very;
complex;
code;
Good example:
 
/**
 * Returns x raised to the n-th power.
 *
 * @param {number} x The number to raise.
 * @param {number} n The power, must be a natural number.
 * @return {number} x raised to the n-th power.
 */
function pow(x, n) {
  ...
}
... 5 lines
 

Questions    
Ninja!

        A B C D E F
🔔
1/3