Message from JavaScript discussions

January 2019

— 

'use strict';

let sum = 0;

console.time('loop');
for (let i = 0; i < 100000000; ++i) {
sum += i;
}
console.log(sum);
console.timeEnd('loop');

Message permanent page

— 

'use strict';

const sum = (i, acc) =>
i < 100000000
? sum(i + 1, i + acc)
: acc;

console.time('ptc');
console.log(sum(0, 0));
console.timeEnd('ptc');

— Definitly, it will be inlined

— How?

— It can't

— It will be transformed into loop

— Yes, but that's not what function inlining is

— That's what proper tail calls are

— I write bound functions, when i need to bind to some context, not because i want to optimize a loop or shorten the syntax

Message permanent page

— Wat

— Never use this

— It's garbage