Interesting Facts About JavaScript
Last Updated :
23 Nov, 2024
JavaScript (often abbreviated as JS) is one of the most popular programming languages in the world. It is an interpreted, high-level programming language that follows ECMAScript. It powers interactive websites and is packed with amazing features that make it special and powerful.

Interesting Facts About JavaScript
Here are some interesting facts about JavaScript
- JavaScript Was Created in Just 10 Days: JavaScript was developed by Brendan Eich in 1995 for Netscape. He completed the first version in a whopping 10 days to meet the pressing needs of the browser market!
- JavaScript Is Not the Same as Java: Despite the similar names, JavaScript and Java are two entirely different languages. Java is a statically typed, object-oriented language, while JavaScript is dynamically typed and versatile in both functional and object-oriented programming.
- Interpreted Language: JavaScript is interpreted, not compiled, which means it runs line-by-line in the browser. This enables real-time feedback and rapid development.
- Dynamic Typing with Structure: In JS variables don’t need an explicit type definition when declared, unlike strict languages such as C or C++. However, it offers more structure than languages like Python with the addition of let, const, and var keywords for variable declarations.
- The Foundation of Modern Web: Most web applications today rely on JavaScript to provide interactive, dynamic content, making it a core pillar of the web alongside HTML and CSS.
- Runs Everywhere: Initially designed for client-side scripting, JavaScript now powers both client and server-side applications with the rise of technologies like Node.js.
JavaScript and Browsers
- JavaScript Engines: Each major browser has its own JavaScript engine for running code. For instance
- Google Chrome uses V8.
- Firefox uses SpiderMonkey.
- Safari uses JavaScriptCore.
- Edge uses Chakra.
- Asynchronous Capabilities: JavaScript is single-threaded, meaning it can execute one line of code at a time. However, its asynchronous capabilities (via callbacks, promises, and async/await) enable non-blocking code execution, making it ideal for modern applications.
Fun Features in JavaScript
Numbers: 64-Bit Floating Point by Default
In JavaScript, all numbers (integers and floating-point values) are stored as 64-bit floating-point numbers based on the IEEE 754 standard. Unlike C++ or Java, there are no distinct int, float, or double types.
Bitwise Operations: JavaScript performs bitwise operations on 32-bit signed integers. So to do the operation it needs to convert 64 bit numbers.
- Converts the 64-bit floating-point number to a 32-bit binary number.
- Executes the operation.
- Converts the result back to a 64-bit floating-point number.
JavaScript
let n = 5.5; // Stored as a 64-bit floating-point number
let res = n | 0; // Bitwise OR operation
console.log(res); // Output: 5
Logical Operators Work with Numbers
JavaScript’s logical operators (&&, ||, !) work with numbers and other types, not just booleans, treating falsy and truthy values as logical states.
- Falsy Values: false, 0, -0, “” (empty string), null, undefined, NaN, and document.all are considered falsy.
- Truthy Values: Any value not listed above, including non-zero numbers and non-empty strings, is considered truth.
JavaScript
console.log(0 && 5);
console.log(5 && 10);
console.log(5 || 0);
Everything Is an Object (Sort of)
In JavaScript, Functions are objects, arrays are objects, and even primitive values can behave like objects temporarily when you try to access properties on them.
JavaScript
let s = "hello";
console.log(s.length);
// Example with a number
let x = 42;
console.log(x.toString());
// Example with a boolean
let y = true;
console.log(y.toString());
/* Internal Working of primitives
to be treeated as objects
// Temporary wrapper object
let temp = new String("hello");
console.log(temp.length); // 5
// The wrapper is discarded after use
temp = null; */
Arrays Are Objects
JavaScript arrays are technically objects, which allows them to have non-integer keys.
JavaScript
const a = [1, 2, 3];
a["key"] = "value";
console.log(a.key);
In most languages, arrays are strictly defined structures and don’t allow such behavior.
Type Coercion
JavaScript has a unique way of handling types, often resulting in unexpected results
JavaScript
console.log(1 + "2");
console.log("5" - 2);
Output
"12"
3
This automatic conversion between types is called type coercion.
Hoisting
JavaScript moves declarations to the top of their scope before executing the code called hoisting. However, only the declaration is hoisted, not the initialization.
JavaScript
var greeting; // Declaration is hoisted to the top
console.log(greeting); // At this point, `greeting` is undefined
greeting = "Hello, World!"; // Initialization happens here
console.log(greeting); // Now, it logs "Hello, World!"
Outputundefined
Hello, World!
In Python or C++, referencing a variable before its declaration results in an error.
NaN Is a Number
In JavaScript, NaN (Not-a-Number) is actually of type number. It’s used to represent an invalid number, which can be confusing for beginners.
JavaScript
console.log(typeof NaN);
console.log(NaN === NaN);
A character is also a string
There is no separate type for characters. A single character is also a string.
JavaScript
let s1 = "gfg"; // String
let s2 = 'g'; // Character
console.log(typeof s1);
console.log(typeof s2);
Equality Quirks
JavaScript has two equality operators:
- Double equals (==) performs type conversion before comparing.
- Triple equals (===) checks both type and value without type conversion.
JavaScript
console.log(0 == "0");
console.log(0 === "0");
Output
true
false
Variables Without var
Declaring variables without var, let, or const automatically places them in the global scope. This can lead to unexpected behavior
JavaScript
function variable() {
n = 10;
}
variable();
console.log(n);
Output
10
But ‘n’ is now a global variable.
Related Topics
Similar Reads
Interesting Facts about JavaScript Arrays
Let us talk about some interesting facts about JavaScript Arrays that can make you an efficient programmer. Arrays are ObjectsJavaScript arrays are actually specialized objects, with indexed keys and special properties. They have a length property and are technically instances of the Array construct
3 min read
Interesting Facts About JavaScript Strings
Let's see some interesting facts about JavaScript strings that can help you become an efficient programmer. Strings are ImmutableIn JavaScript, strings are immutable, which means once you create a string, you cannot change its characters individually. Any operation that appears to modify a string, l
3 min read
Interesting Facts about JavaScript Functions
Let us talk about some interesting facts about JavaScript Functions that can make you an efficient programmer. Functions Are First-Class CitizensJavaScript treats functions as first-class citizens, meaning they can be: Stored in variablesPassed as arguments to other functionsReturned from other func
4 min read
Interesting Facts about Object in JavaScript
Let's see some interesting facts about JavaScript Objects that can help you become an efficient programmer. JavaSctipt Objects internally uses Hashing that makes time complexities of operations like search, insert and delete constant or O(1) on average. It is useful for operations like counting freq
4 min read
Explain about IIFEs in JavaScript
In this article, you will learn about JavaScript immediately invoked function expressions (IIFE). A JavaScript immediately Invoked Function Expression is a function defined as an expression and executed immediately after creation. The following shows the syntax of defining an immediately invoked fun
3 min read
Abstraction in JavaScript
In JavaScript, Abstraction can be defined as the concept of hiding the inner complex workings of an object and exposing only the essential features to the user. Hiding Complexity: Implementation is hidden, it shows only the necessary details.Modularity: Code is organized in a reusable form, which im
4 min read
Interesting Code Snippets in JavaScript
JavaScript is a flexible and powerful programming language that can solve problems in clever and simple ways. Here are some fun JavaScript code snippets that highlight its features and quirks. Whether you're a beginner or an experienced developer, these examples will spark your interest. 1. Flatteni
5 min read
Functions in JavaScript
Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code. It can take inputs, perform actions, and return outputs. [GFGTABS] JavaScript function sum(x, y) { return x + y; } console.log(sum(6, 9)); [/GFGTABS]Output1
5 min read
JavaScript Anonymous Functions
An anonymous function is simply a function that does not have a name. Unlike named functions, which are declared with a name for easy reference, anonymous functions are usually created for specific tasks and are often assigned to variables or used as arguments for other functions. In JavaScript, you
3 min read
All about Functions and Scopes in JavaScript
In this article, we will cover all the basic concepts of JS functions, callbacks, scopes, closures in-depth which would help you to - understand different types of function declarations.make better use of functions.understand how different scopes and scope chain works in JS.learn about closures and
10 min read