Hi folks! ๐ Welcome to yet another session of free ka gyan ๐ก (because who doesnโt love free wisdom?). You might be thinking, โWhy another session?โ...
Just another average coder sharing knowledge because I have nothing to do. I break code, fix it, and learn along the way. (Please, someone hire meโpromise I wonโt break everything!)
You're almost right! Just a small clarification: IIFEs are "Immediately Invoked Function Expressions" because they execute immediately after being defined, but this doesn't make them recursive. Recursion occurs when a function calls itself from within its own body. Also, you're absolutely correct that IIFEs don't have to be anonymousโthey can be named as well.
Small examples: Anonymous IIFE:
(function(){console.log("This is an anonymous IIFE!");})();
Named IIFE:
(functionnamedIIFE(){console.log("This is a named IIFE!");})();
Self invoking would mean they invoke themselves. They do not. They are invoked the same way as any other function - from outside (i.e. not by the function itself)
A "self invoking function" is - by definition - recursive.
Just another average coder sharing knowledge because I have nothing to do. I break code, fix it, and learn along the way. (Please, someone hire meโpromise I wonโt break everything!)
You're correct in distinguishing between IIFEs (Immediately Invoked Function Expressions) and recursive functions, and the misuse of the term "self-invoking."
An IIFE is not "self-invoking" in the literal sense. It's explicitly invoked by the surrounding parentheses (()), which execute the function immediately upon definition. The function does not invoke itself; it is invoked by wrapping syntax.
On the other hand, recursive functions do indeed "self-invoke" because they call themselves within their own body, typically with modified arguments, until a base case is met to stop the recursion. I hope that clarifies the statement.
Your string reversing code is using split. This will break with some unicode characters (try reversing a string containing emojis). Much better to spread the string to an array ([...str]) - not perfect, but much better.
Just another average coder sharing knowledge because I have nothing to do. I break code, fix it, and learn along the way. (Please, someone hire meโpromise I wonโt break everything!)
Thank you for your input! You are absolutely correct that using splitwill not handle Unicode characters like emojis or certain symbols effectively. Instead, ([...str]) is indeed a better option for such cases.
To elaborate for the readers, when using split, the string is divided into individual characters based on UTF-16 code units. Emojis, however, are surrogate pairs consisting of two UTF-16 code units, which causes splitto fail. On the other hand, the spread operator treats Unicode characters as single entities, regardless of how many UTF-16 code units they consist of.
I appreciate you pointing this out, and Iโll also edit the code to ensure it handles Unicode characters properly.
Just another average coder sharing knowledge because I have nothing to do. I break code, fix it, and learn along the way. (Please, someone hire meโpromise I wonโt break everything!)
Thank you for sharing your thoughts! I just wanted to clarify a small point about JavaScript. While it's a common misconception, JavaScript technically doesn't use pass-by-reference. Instead, it uses pass-by-value for everything, but with objects (including arrays and functions), the "value" that's passed is actually a reference to the memory location. This is why it sometimes behaves like pass-by-reference.
To break it down: Pass-by-Value (Primitives): A copy of the value is passed, so changes inside the function donโt affect the original variable (e.g., numbers, strings, booleans).
Objects (Reference-like behavior): A copy of the reference is passed, which allows changes to the object's properties to reflect outside the function. However, if you reassign the parameter inside the function, the original reference remains unchanged.
Itโs a subtle distinction, but itโs a good one to keep in mind! Hope this helps! ๐
I'm new to software development and currently studying at the University of Minnesota's Software Engineer Coding Bootcamp. I'm passionate about learning new technologies and building my skills in codi
Just another average coder sharing knowledge because I have nothing to do. I break code, fix it, and learn along the way. (Please, someone hire meโpromise I wonโt break everything!)
That's a wonderful approach! JavaScript can be a bit challenging initially, but with consistent practice, you'll master it in no time. One piece of advice: try to learn concepts through practical examples. Feel free to reach out if you have any questions or need help along the way. You've got this!
Just another average coder sharing knowledge because I have nothing to do. I break code, fix it, and learn along the way. (Please, someone hire meโpromise I wonโt break everything!)
Thank you for pointing this out! Youโre absolutely correctโthe current polyfills for mapand filterdo not include support for the optional thisArgparameter, which is essential for fully replicating the behavior of these functions.
The thisArgallows developers to provide a custom this context for the callback function, which can be crucial in scenarios where the callback depends on a specific execution context. Without it, the polyfills may fail to handle certain use cases properly, making them incomplete.
I really appreciate you bringing this to my attention and highlighting its importance!
We're a place where coders share, stay up-to-date and grow their careers.
IIFEs are not self invoking (that would make them recursive functions), and they don't have to be anonymous
Hi Jon,
You're almost right! Just a small clarification: IIFEs are "Immediately Invoked Function Expressions" because they execute immediately after being defined, but this doesn't make them recursive. Recursion occurs when a function calls itself from within its own body. Also, you're absolutely correct that IIFEs don't have to be anonymousโthey can be named as well.
Small examples:
Anonymous IIFE:
Named IIFE:
Self invoking would mean they invoke themselves. They do not. They are invoked the same way as any other function - from outside (i.e. not by the function itself)
A "self invoking function" is - by definition - recursive.
Calling IIFEs self-invoking is entirely wrong.
You're correct in distinguishing between IIFEs (Immediately Invoked Function Expressions) and recursive functions, and the misuse of the term "self-invoking."
An IIFE is not "self-invoking" in the literal sense. It's explicitly invoked by the surrounding parentheses (()), which execute the function immediately upon definition. The function does not invoke itself; it is invoked by wrapping syntax.
On the other hand, recursive functions do indeed "self-invoke" because they call themselves within their own body, typically with modified arguments, until a base case is met to stop the recursion. I hope that clarifies the statement.
Your string reversing code is using
split. This will break with some unicode characters (try reversing a string containing emojis). Much better to spread the string to an array ([...str]) - not perfect, but much better.Hi Jon,
Thank you for your input! You are absolutely correct that using
splitwill not handle Unicode characters like emojis or certain symbols effectively. Instead,([...str])is indeed a better option for such cases.To elaborate for the readers, when using
split, the string is divided into individual characters based on UTF-16 code units. Emojis, however, are surrogate pairs consisting of two UTF-16 code units, which causessplitto fail. On the other hand, the spread operator treats Unicode characters as single entities, regardless of how many UTF-16 code units they consist of.I appreciate you pointing this out, and Iโll also edit the code to ensure it handles Unicode characters properly.
Thank you again for sharing your thoughts!
Be careful answering this one. JavaScript only has pass by value. Kind of a trick question
Hi Jon!
Thank you for sharing your thoughts! I just wanted to clarify a small point about JavaScript. While it's a common misconception, JavaScript technically doesn't use pass-by-reference. Instead, it uses pass-by-value for everything, but with objects (including arrays and functions), the "value" that's passed is actually a reference to the memory location. This is why it sometimes behaves like pass-by-reference.
To break it down:
Pass-by-Value (Primitives): A copy of the value is passed, so changes inside the function donโt affect the original variable (e.g., numbers, strings, booleans).
Objects (Reference-like behavior): A copy of the reference is passed, which allows changes to the object's properties to reflect outside the function. However, if you reassign the parameter inside the function, the original reference remains unchanged.
Itโs a subtle distinction, but itโs a good one to keep in mind! Hope this helps! ๐
Just now learning Javascript hopefully I can learn most of these values soon to better understand these questions.
That's a wonderful approach! JavaScript can be a bit challenging initially, but with consistent practice, you'll master it in no time. One piece of advice: try to learn concepts through practical examples. Feel free to reach out if you have any questions or need help along the way. You've got this!
The polyfills for
mapandfilterare both missing the optionalthisArg. Without this, they're not viable polyfills for these functions.Thank you for pointing this out! Youโre absolutely correctโthe current polyfills for
mapandfilterdo not include support for the optionalthisArgparameter, which is essential for fully replicating the behavior of these functions.The
thisArgallows developers to provide a custom this context for the callback function, which can be crucial in scenarios where the callback depends on a specific execution context. Without it, the polyfills may fail to handle certain use cases properly, making them incomplete.I really appreciate you bringing this to my attention and highlighting its importance!