Scoping rules with (or without) var are the weirdest:
// Prints the value of a.functionprintA(){console.log(a);}// Prints '1'functionprint1(){vara=1;printA();}// Prints '2'functionprint2(){vara=2;printA();}// Prints whatever the value of b in the caller's scope is.functionprintB(){a=b;printA();}// Prints 3.functionprint3(){varb=3;printB();}// Print 4, then 5.functionprint45(){varb=4;vara=5;printB();printA();// Ha, no it doesn't, it prints 4 twice, and now:assert(a===4);}
Of course, I made a mistake on it (now corrected), but still. If you want to see something batshit insane with scoping and hoisting, you can try and get your head around this:
Scoping rules with (or without) var are the weirdest:
you have just blown my tiny mind
Of course, I made a mistake on it (now corrected), but still. If you want to see something batshit insane with scoping and hoisting, you can try and get your head around this:
😭
loved