Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • Software and Tools
    • School Learning
    • Practice Coding Problems
  • Go Premium
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Interesting Facts About JavaScript
Next article icon

Interesting Facts About JavaScript Data Types

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

JavaScript (often abbreviated as JS) is one of the most popular programming languages in the world. It comes with its unique take on data types that sets it apart from languages like C, C++, Java, or Python. Understanding how JavaScript handles data types will be very interesting, which can help you write better, more efficient code.

Here are some interesting facts about JavaScript Data Types

Only One Number Type

Unlike languages like C++, Java, or Python, where numbers are categorized as int, float, or double, JavaScript has just one number type: a 64-bit floating-point number (IEEE 754 standard).

  • This means all integers and decimals are treated the same.
  • Integer precision is accurate up to 15 digits
JavaScript
console.log(999999999999999);
console.log(9999999999999999); 

Output
999999999999999
10000000000000000

In C++ or Java, you must explicitly define the type (e.g., int or float), and exceeding the type’s range results in an error. JavaScript silently switches to floating-point behaviour.

Dynamic Typing

JavaScript is dynamically typed, meaning a variable's type can change at runtime, unlike statically typed languages like Java or C++.

JavaScript
let data = 42;      // Initially a number
data = "Hello";     // Now a string
data = true;        // Now a boolean

Primitive vs. Reference Types

JavaScript divides its data types into primitive and reference types

  • Primitive Types: Stored directly in memory and are immutable. Examples of primitive type are number, string, boolean, undefined, null, symbol, bigint
  • Reference Types: Objects and arrays are stored as references.
JavaScript
let obj1 = { a: 1 };
let obj2 = obj1;
obj2.a = 2;
console.log(obj1.a);

Output
2

undefined and null Are Separate Types

JavaScript treats undefined and null as distinct types, which can confuse developers from other languages.

  • undefined: Represents a variable that has been declared but not assigned a value.
  • null: Represents an intentional absence of a value.
JavaScript
let a;
console.log(a);     
let b = null;
console.log(b);

Output
undefined
null

In many languages, null or None is the default for uninitialized variables. JavaScript’s separate undefined type adds a layer of complexity.

typeof null Returns "object"

One unusual behaviour is typeof operator identifies null as an "object". This is a well-known bug from the early days of JavaScript but remains for backward compatibility.

JavaScript
console.log(typeof null);

Output
object

This behavior is peculiar to JavaScript and isn’t seen in other languages.

Bitwise Operations and 32-Bit Conversion

In JavaScript, all numbers are stored as 64-bit floating-point numbers, as defined by the IEEE 754 standard. However, bitwise operations in JavaScript are performed on 32-bit signed integers. This involves a multi-step conversion process

  • Conversion to 32-Bit Signed Integer: When a bitwise operation is executed, the 64-bit floating-point number is converted to a 32-bit signed binary number.
  • Bitwise Operation: The operation (e.g., AND, OR, XOR, etc.) is performed using the 32-bit binary representation.
  • Conversion Back to 64-Bit: The result is converted 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

Output
5

The && Operator Returns Actual Values

Unlike many other languages where the && (logical AND) operator strictly evaluates to a boolean (true or false), in JavaScript, it returns the actual value of the last operand evaluated. The behavior depends on whether the first operand is true or false

  • If the First Operand is False: The operation short-circuits, and the first operand is returned without evaluating the second.
  • If the First Operand is True: The second operand is evaluated and returned.
JavaScript
let x = 5;
let y = 0;

// 5 (true) && 0 (false)
let res = x && y; 
console.log(res); 

// 5 (true) && 10 (true)
res = x && 10;
console.log(res);

Output
0
10

NaN Is a Number

JavaScript includes NaN (Not-a-Number) as a value of type number.

JavaScript
console.log(typeof NaN);
console.log(NaN === NaN); 

Output
number
false

Most languages like Python or Java handle NaN differently and don’t classify it as a number.

BigInt: Numbers Beyond 64-Bit Precision

To handle integers larger than 64 bits, JavaScript introduced the BigInt type in ES2020.

JavaScript
const bigN = 123456789012345678901234567890n;
console.log(bigN + 1n); 

Output
123456789012345678901234567891n

While Python supports arbitrary precision integers by default, languages like Java or C++ require libraries to handle such large numbers.

Strings as Immutable Primitives

In JavaScript, strings are immutable primitives, even though they can be accessed like arrays.

JavaScript
let s = "Hello";
s[0] = "h"; // No effect
console.log(s);

Output
Hello

While string immutability exists in Java, JavaScript’s syntax for accessing characters like arrays is unusual.

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);

Output
string
string

Symbol: Unique Identifiers

JavaScript introduces the symbol type for creating unique identifiers, a feature not commonly seen in other languages.

JavaScript
const sym1 = Symbol("id");
const sym2 = Symbol("id");
console.log(sym1 === sym2);

Output
false

Symbols ensure uniqueness, which is helpful for avoiding naming conflicts in object properties.

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; */

Output
5
42
true

Falsy and Truthy Values

JavaScript’s loose typing leads to unique rules for truthiness and falsiness:

  • Falsy Values: false, 0, -0, "", null, undefined, NaN, document.all
  • Truthy Values: Everything else.
JavaScript
if ("0") console.log("Truthy");
if (0) console.log("Falsy");  //no output

Output
Truthy

In this code, because 0 is false it will not execute the 2nd if statement as if statement runs only if condition is true.

This behavior doesn’t exist in strongly-typed languages like C++ or Java.

The && Operator Returns Actual Values

Type Coercion and Dual Equality

JavaScript allows automatic type conversion during comparisons (==), which can yield surprising results.

JavaScript
console.log(5 == "5");  
console.log(5 === "5");

Output
true
false

Most languages enforce strict type equality for comparisons.

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); 

Output
value

In most languages, arrays are strictly defined structures and don’t allow such behavior.

Dynamic Object Properties

JavaScript objects can have properties added, modified, or removed at runtime.

JavaScript
const obj = {};
obj.newProperty = "Hello";
console.log(obj.newProperty); // Output: Hello

Output
Hello

Unlike Java or C++, you don’t need to predefine object structure in JavaScript.


Next Article
Interesting Facts About JavaScript

S

souravsharma098
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-basics
  • JavaScript Facts
  • JavaScript-QnA

Similar Reads

    Interesting Facts About JavaScript
    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 A
    5 min read
    Interesting Facts About JavaScript
    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 A
    5 min read
    Interesting Facts About JavaScript
    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 A
    5 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 frequ
    4 min read
    Introduction to Built-in Data Structures in JavaScript
    JavaScript (JS) is the most popular lightweight, interpreted compiled programming language, and might be your first preference for Client-side as well as Server-side developments. Let's see what inbuilt data structures JavaScript offers us: Data Structure Internal Implementation Static or Dynamic Ja
    2 min read
    JavaScript Type Conversion
    In JavaScript Type Conversion can be defined as converting the data type of the variables from one type to the other manually by the programmer(explicitly) or automatically by the JavaScript(implicitly).Implicit Type Conversion (Coercion): Implicit Type Conversion occurs automatically by the JavaScr
    4 min read
`; $(commentSectionTemplate).insertBefore(".article--recommended"); } loadComments(); }); }); function loadComments() { if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • DSA Tutorial
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences