4/11/26, 11:14 PM JavaScript Datatypes
Tutorials References Exercises Get Certified Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
JavaScript Datatypes
❮ Previous Next ❯
JavaScript has 8 Datatypes
A JavaScript variable can hold 8 types of data:
Type Description
String A text of characters enclosed in quotes
Number A number representing a mathematical value
Bigint A number representing a large integer
Boolean A data type representing true or false
Object A collection of key-value pairs of data
Undefined A primitive variable with no assigned value
Null A primitive value representing object absence
Symbol A unique and primitive identifier
Examples
// String
let color = "Yellow";
let lastName = "Johnson";
// Number
[Link] 1/10
4/11/26, 11:14 PM JavaScript Datatypes
let length = 16;
Tutorials= 7.5;References
let weight Exercises Get Certified Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
// BigInt
let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)
// Boolean
let x = true;
let y = false;
// Object
const person = {firstName:"John", lastName:"Doe"};
// Array object
const cars = ["Saab", "Volvo", "BMW"];
// Date object
const date = new Date("2022-03-25");
// Undefined
let x;
let y;
// Null
let x = null;
let y = null;
// Symbol
const x = Symbol();
const y = Symbol();
The typeof Operator
You can use the JavaScript typeof operator to find the type of a JavaScript variable.
The typeof operator returns the type of a variable or an expression:
[Link] 2/10
4/11/26, 11:14 PM JavaScript Datatypes
Tutorials
Example References Exercises Get Certified Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
typeof "" // Returns "string"
typeof "John" // Returns "string"
typeof "John Doe" // Returns "string"
Try it Yourself »
Example
typeof 0 // Returns "number"
typeof 314 // Returns "number"
typeof 3.14 // Returns "number"
typeof (3) // Returns "number"
typeof (3 + 4) // Returns "number"
Try it Yourself »
JavaScript Strings
A string (a text string) is a series of characters like "John Doe".
Strings are written with quotes. You can use single or double quotes:
Example
// Using double quotes:
let carName1 = "Volvo XC60";
// Using single quotes:
let carName2 = 'Volvo XC60';
[Link] 3/10
4/11/26, 11:14 PM JavaScript Datatypes
Try it Yourself »
Tutorials References Exercises Get Certified Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
You can use quotes inside a string, as long as they don't match the quotes surrounding the
string:
Example
// Single quote inside double quotes:
let answer1 = "It's alright";
// Single quotes inside double quotes:
let answer2 = "He is called 'Johnny'";
// Double quotes inside single quotes:
let answer3 = 'He is called "Johnny"';
Try it Yourself »
You will learn a lot more about JavaScript Strings later in this tutorial.
JavaScript Numbers
All JavaScript numbers are stored as decimal numbers (floating point).
Numbers can be written with, or without decimals:
Example
// With decimals:
let x1 = 34.00;
[Link] 4/10
4/11/26, 11:14 PM JavaScript Datatypes
// Without decimals:
Tutorials
let x2 = 34; References Exercises Get Certified Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Try it Yourself »
Exponential Notation
Extra large or extra small numbers can be written with scientific (exponential) notation:
Example
let y = 123e5; // 12300000
let z = 123e-5; // 0.00123
Try it Yourself »
REMOVE ADS
JavaScript Booleans
JavaScript booleans can only have one of two values: true or false
The boolean value of an expression is the basis for JavaScript comparisons.
Given that x = 5, the table below explains comparison:
Description Expression Returns
Equal to (x == 8) false
Not equal to (x != 8) true
[Link] 5/10
4/11/26, 11:14 PM JavaScript Datatypes
Greater Tutorials
than References (xExercises
> 8) Get false
Certified Sign In
Less than (x < 8) true
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Example
let x = 5;
(x == 8); // equals false
(x != 8); // equals true
Try it Yourself »
All JavaScript comparison operators (like ==, !=, <, >) return true or false from the comparison.
Datatype undefined
In computer programs, variables are often declared without a value. The value can be
something that has to be calculated, or something that will be provided later, like user input.
A variable without a value has the datatype undefined .
A variable without a value also has the value undefined .
Example
let carName;
Try it Yourself »
[Link] 6/10
4/11/26, 11:14 PM JavaScript Datatypes
Empty
Values
Tutorials References Exercises Get Certified Sign In
HTML CSS
An empty value JAVASCRIPT SQL
has nothing to do with PYTHON
undefined . JAVA PHP HOW TO [Link] C
An empty string has both a legal value and a type.
Example
let car = ""; // The value is "", the typeof is "string"
Try it Yourself »
You will learn a lot more about Data Types later in this tutorial.
?
Exercise
In JavaScript, what is the data type of the following variable?
let x = 7.5
Decimal
Number
Integer
Float
Submit Answer »
[Link] 7/10
4/11/26, 11:14 PM JavaScript Datatypes
❮ Previous
Tutorials References Exercises
Sign in to track progress
Get Certified Sign In
Next ❯
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
COLOR PICKER
REMOVE ADS
-->
PLUS SPACES
[Link] 8/10
4/11/26, 11:14 PM JavaScript Datatypes
Tutorials References
GET CERTIFIED
Exercises
FOR TEACHERS
Get Certified Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
BOOTCAMPS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
AngularJS Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
[Link] 9/10
4/11/26, 11:14 PM JavaScript Datatypes
Tutorials References
FORUM ABOUT
Exercises
ACADEMY
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
Sign In
learning.
HTML
CSSTutorials,JAVASCRIPT SQL are constantly
references, and examples PYTHON reviewed JAVA PHP but weHOW
to avoid errors, cannotTO
warrant [Link]
full C
correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and
privacy policy.
Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by [Link].
[Link] 10/10