Picture of Mehul Kar

Mehul Kar

Link to Twitter profile Link to email Link to RSS feed

Apr 18, 2022

TIL: Creating Globals

programming javascript

Today I learned you can create globals by passing unnecessary arguments to a function in javascript.

For example:

function myFunc(a) {
console.log(a);
}

myFunc(123, (i=100));

console.log(i);

Calling this function with that second argument expression will assign a global i to the value 100.

Want to talk about this post? Email me or send me a toot @mehulkar.