Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • 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:
JavaScript Course Operators in JavaScript
Next article icon

JavaScript Data Types

Last Updated : 08 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In JavaScript, each value has a data type, defining its nature (e.g., Number, String, Boolean) and operations. Data types are categorized into Primitive (e.g., String, Number) and Non-Primitive (e.g., Objects, Arrays).

Primitive Data Type

1. Number

The Number data type in JavaScript includes both integers and floating-point numbers. Special values like Infinity, -Infinity, and NaN represent infinite values and computational errors, respectively.

JavaScript
let n1 = 2; console.log(n1)  let n2 = 1.3; console.log(n2)  let n3 = Infinity; console.log(n3)  let n4 = 'something here too' / 2; console.log(n4) 

Output
2 1.3 Infinity NaN 

2. String

A String in JavaScript is a series of characters that are surrounded by quotes. There are three types of quotes in JavaScript, which are.

JavaScript
let s1 = "Hello There"; console.log(s1);   let s2 = 'Single quotes work fine'; console.log(s2);   let s3 = `can embed ${s1}`; console.log(s3);  

Output
Hello There Single quotes work fine can embed Hello There 

There’s no difference between ‘single’ and “double” quotes in JavaScript. Backticks provide extra functionality as with their help of them we can embed variables inside them.

3. Boolean

The boolean type has only two values i.e. true and false.

JavaScript
let b1 = true; console.log(b1);    let b2 = false; console.log(b2);   

Output
true false 

4. Null

The special null value does not belong to any of the default data types. It forms a separate type of its own which contains only the null value.

JavaScript
let age = null; console.log(age) 

Output
null 

The ‘null’ data type defines a special value that represents nothing, or empty value.

5. Undefined

A variable that has been declared but not initialized with a value is automatically assigned the undefined value. It means the variable exists, but it has no value assigned to it.

JavaScript
let a; console.log(a); 

Output
undefined 

6. Symbol (Introduced in ES6)

Symbols, introduced in ES6, are unique and immutable primitive values used as identifiers for object properties. They help create unique keys in objects, preventing conflicts with other properties.

JavaScript
let s1 = Symbol("Geeks"); let s2 = Symbol("Geeks"); console.log(s1 == s2);    

Output
false 

7. BigInt (Introduced in ES2020)

BigInt is a built-in object that provides a way to represent whole numbers greater than 253. The largest number that JavaScript can reliably represent with the Number primitive is 253, which is represented by the MAX_SAFE_INTEGER constant.

JavaScript
let b = BigInt("0b1010101001010101001111111111111111"); console.log(b); 

Non-Primitive Data Types

The data types that are derived from primitive data types are known as non-primitive data types. It is also known as derived data types or reference data types.

1. Object

JavaScript objects are key-value pairs used to store data, created with {} or the new keyword. They are fundamental as nearly everything in JavaScript is an object.

JavaScript
let gfg = {     type: "Company",     location: "Noida" } console.log(gfg.type) 

Output
Company 

2. Arrays

An Array is a special kind of object used to store an ordered collection of values, which can be of any data type.

JavaScript
let a1 = [1, 2, 3, 4, 5]; console.log(a1);  let a2 = [1, "two", { name: "Object" }, [3, 4, 5]]; console.log(a2); 

Output
[ 1, 2, 3, 4, 5 ] [ 1, 'two', { name: 'Object' }, [ 3, 4, 5 ] ] 

3. Function

A function in JavaScript is a block of reusable code designed to perform a specific task when called.

JavaScript
// Defining a function to greet a user function greet(name) { return "Hello, " + name + "!"; } // Calling the function console.log(greet("Ajay")); 

Output
Hello, Ajay! 

4. Date Object

The Date object in JavaScript is used to work with dates and times, allowing for date creation, manipulation, and formatting.

JavaScript
// Creating a new Date object for the current date and time let currentDate = new Date(); // Displaying the current date and time console.log(currentDate);  

Output
2025-03-08T06:23:33.202Z 

5. Regular Expression

A RegExp (Regular Expression) in JavaScript is an object used to define search patterns for matching text in strings.

JavaScript
// Creating a regular expression to match the word "hello" let pattern = /hello/; // Testing the pattern against a string let result = pattern.test("Hello, world!"); // Returns true because "Hello" matches the pattern console.log(result);  

Output
false 

Interesting Facts about Data Types

1. Dynamically Typed : JavaScript Variables are not bound to a specific data type. Mainly data type is stored with value (not with variable name) and is decided & checked at run time.

JavaScript
let x = 42;    console.log(x)  x = "hello";   console.log(x)  x = [1, 2, 3] console.log(x) 

Output
42 hello [ 1, 2, 3 ] 

2. 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 

3. NaN is not equal to itself: NaN Stands for “Not-a-Number”, It is used to represent a computational error. NaN is technically of type number.

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

Output
number false 

4. A Symbol is Never Equal to Another One : Symbol is a unique and immutable data type often used for creating private properties and methods. Symbols are never equal to any other Symbol.

JavaScript
let s1 = Symbol("abc"); let s2 = Symbol("abc"); console.log(s1 === s2); 

Output
false 

5. Undefined and Null: undefined represents a variable that has been declared but not assigned, while null is an explicit assignment representing “no value”.

6. Integers are Floating are Numbers only. There is only one type number that covers both integers and floating point numbers.

JavaScript
let x = 42;     // Integer let y = 42.5;   // Floating-point  console.log(typeof x);  console.log(typeof y); 

Output
number number 

7. 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 



Next Article
JavaScript Course Operators in JavaScript
author
immukul
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-basics
  • JavaScript-Course

Similar Reads

  • Introduction to JavaScript Course - Learn how to build a task tracker using JavaScript
    This is an introductory course about JavaScript that will help you learn about the basics of javascript, to begin with, the dynamic part of web development. You will learn the basics like understanding code structures, loops, objects, etc. What this course is about? In this course we will teach you
    4 min read
  • JavaScript Course What is JavaScript ?
    JavaScript is a very famous programming language that was originally started in the year of 1995 with the motive of making web pages alive. It is also an essential part of the web developer skillset. In simple terms, if you want to learn web development then learn HTML & CSS before starting JavaScri
    3 min read
  • JavaScript Hello World
    The JavaScript Hello World program is a simple tradition used by programmers to learn the new syntax of a programming language. It involves displaying the text "Hello, World!" on the screen. This basic exercise helps you understand how to output text and run simple scripts in a new programming envir
    2 min read
  • JavaScript Course Understanding Code Structure in JavaScript
    Inserting JavaScript into a webpage is much like inserting any other HTML content. The tags used to add JavaScript in HTML are <script> and </script>. The code surrounded by the <script> and </script> tags is called a script blog. The 'type' attribute was the most important a
    3 min read
  • JavaScript Course Variables in JavaScript
    Variables in JavaScript are containers that hold reusable data. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is only a name given to a memory location, all the operations done on the variable effects that memory loca
    4 min read
  • JavaScript Data Types
    In JavaScript, each value has a data type, defining its nature (e.g., Number, String, Boolean) and operations. Data types are categorized into Primitive (e.g., String, Number) and Non-Primitive (e.g., Objects, Arrays). Primitive Data Type1. NumberThe Number data type in JavaScript includes both inte
    6 min read
  • JavaScript Course Operators in JavaScript
    An operator is capable of manipulating a certain value or operand. Operators are used to performing specific mathematical and logical computations on operands. In other words, we can say that an operator operates the operands. In JavaScript, operators are used for comparing values, performing arithm
    7 min read
  • JavaScript Course Interaction With User
    Javascript allows us the privilege to which we can interact with the user and respond accordingly. It includes several user-interface functions which help in the interaction. Let's take a look at them one by one. JavaScript Window alert() Method : It simply creates an alert box that may or may not h
    2 min read
  • JavaScript Course Logical Operators in JavaScript
    logical operator is mostly used to make decisions based on conditions specified for the statements. It can also be used to manipulate a boolean or set termination conditions for loops. There are three types of logical operators in Javascript: !(NOT): Converts operator to boolean and returns flipped
    3 min read
  • JavaScript Course Conditional Operator in JavaScript
    JavaScript Conditional Operators allow us to perform different types of actions according to different conditions. We make use of the 'if' statement. if(expression){ do this; } The above argument named 'expression' is basically a condition that we pass into the 'if' and if it returns 'true' then the
    3 min read
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
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • 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