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.

If you like this post, please share it on Twitter and/or subscribe to my RSS feed. Or don't, that's also ok.