dev3lopcom, llc, official logo 12/8/2022

Connect Now

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

  1. 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.
  2. 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.
  3. Closures: JavaScript functions form closures, which means they have access to variables from their outer (enclosing) functions even after the outer function has returned.
  4. 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.
  5. Prototype-Based Inheritance: Unlike many object-oriented languages, JavaScript uses prototype-based inheritance, allowing objects to inherit properties and methods from other objects.
  6. NaN Is a Number: The typeof NaN is number, which can be counterintuitive. NaN stands for “Not-a-Number,” yet it’s considered a number type.
  7. 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.
  8. Falsy and Truthy Values: JavaScript has several falsy values (false, 0, '', null, undefined, NaN) that evaluate to false in a boolean context. Everything else is truthy.
  9. 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.
  10. 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.
  11. 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!'); })();
  12. Global Object: In a browser environment, the global object is window, while in Node.js, it’s global. Variables declared with var are attached to the global object, unlike those declared with let or const.
  13. this Keyword: The value of this depends on how a function is called. In the global context, this refers to the global object (window), but inside an object method, it refers to that object.
  14. Arrow Functions and this: Arrow functions don’t have their own this context; instead, they lexically inherit this from their parent scope. This makes them handy for use in callbacks to preserve context.
  15. null vs. undefined: null is an intentional absence of any value and can be set by the programmer, while undefined means 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!