Message from JavaScript discussions

January 2019

— It's guaranteed with proper tail calls

— 

That's irrelevant for these cases, there is no inlining going on in the loop nor in the recursive definition

— Inlining is the matter of optimizing compiler, you may make a hint but you dont control it.

— I know, but there is nothing to inline in these examples

— I'll post the code I used

— 

'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');

Message permanent page

— Definitly, it will be inlined

— How?

— It can't

— It will be transformed into loop

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