Recently we had a client reach out and was unsure if their software was Java or JavaScript. We have all been here at least once in our career. Unsure about two buzzwords that sound similar. This lead us to thinking there’s likely a lot of lesser-known facts about JavaScript, like Java is not JavaScript!
Focused on some of the technical aspects that may improve a dev3lopers day.
Here’s a list of 15 examples of 15 lesser-known facts about JavaScript
- JavaScript Is Not Java: Despite their names, Java and JavaScript are unrelated. JavaScript was initially named Mocha and later renamed to LiveScript before Netscape’s marketing team settled on JavaScript to capitalize on Java’s popularity.
- First-Class Functions: Functions in JavaScript are first-class citizens, meaning they can be assigned to variables, passed as arguments, and returned from other functions.
- Closures: JavaScript functions form closures, which means they have access to variables from their outer (enclosing) functions even after the outer function has returned.
- Dynamic Typing: JavaScript is dynamically typed, meaning the same variable can hold different types of values at different times. This flexibility can lead to unexpected behavior if not carefully managed.
- Prototype-Based Inheritance: Unlike many object-oriented languages, JavaScript uses prototype-based inheritance, allowing objects to inherit properties and methods from other objects.
- NaN Is a Number: The typeof NaNisnumber, which can be counterintuitive.NaNstands for “Not-a-Number,” yet it’s considered a number type.
- Double Equals (==) vs. Triple Equals (===): The==operator performs type coercion, converting operands to the same type before comparison. The===operator is stricter and checks both type and value.
- Falsy and Truthy Values: JavaScript has several falsy values (false,0,'',null,undefined,NaN) that evaluate tofalsein a boolean context. Everything else is truthy.
- Hoisting: JavaScript’s default behavior is to hoist variable and function declarations to the top of their containing scope. However, only the declarations are hoisted; initializations remain in place.
- Single-Threaded but Asynchronous: JavaScript runs on a single thread (the event loop) but can handle asynchronous operations like I/O events, thanks to its non-blocking nature and features like Promises and async/await.
- IIFE (Immediately Invoked Function Expressions): JavaScript supports defining and invoking functions immediately, allowing developers to create a private scope. Example: (function() { console.log('This runs immediately!'); })();
- Global Object: In a browser environment, the global object is window, while in Node.js, it’sglobal. Variables declared withvarare attached to the global object, unlike those declared withletorconst.
- thisKeyword: The value of- thisdepends on how a function is called. In the global context,- thisrefers to the global object (- window), but inside an object method, it refers to that object.
- Arrow Functions and this: Arrow functions don’t have their ownthiscontext; instead, they lexically inheritthisfrom their parent scope. This makes them handy for use in callbacks to preserve context.
- nullvs.- undefined:- nullis an intentional absence of any value and can be set by the programmer, while- undefinedmeans a variable has been declared but not assigned a value yet.
These insights reveal some of JavaScript’s quirks and unique characteristics that make it both powerful and sometimes puzzling!
 
					






















