DEV Community

Max Lockwood
Max Lockwood

Posted on • Originally published at maxlockwood.dev

What are the Three Primitive JavaScript Data Types?

Data Types

What are the Three Primitive JavaScript Data Types?

In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods or properties. The term data type refers to the different types of values that a program can operate with. Variables in JavaScript may hold a variety of data types, including numbers, strings, booleans, and more.

JavaScript, unlike many other programming languages, does not specify multiple types of numbers such as integers, short, long, floating-point, and so on.

In this tutorial, you will learn about the three primitive data types available in JavaScript: numbers, strings of text (known as “strings”), and boolean truth values (known as “booleans”).

Numbers

Number represents integer and floating numbers (decimals and exponentials). JavaScript numbers can be written with or without decimals.

let num = 34; // A number without decimals
Enter fullscreen mode Exit fullscreen mode

Floating-Point Numbers

JavaScript numbers can also have decimals.

let price = 29.99;
Enter fullscreen mode Exit fullscreen mode

Strings

JavaScript strings are used for storing and manipulating text.
A string can be any text and must be surrounded by quotes. You can use single or double
quotes.

let name = Tom;
let text = My name is Tom Adams;
Enter fullscreen mode Exit fullscreen mode

You can use quotes inside a string, as long as they don’t match the quotes surrounding
the string.

let text = My name is Tom ;
Enter fullscreen mode Exit fullscreen mode

Booleans

In JavaScript Boolean, you can have one of two values, either true or false.
These are useful when you need a data type that can only have one of two values, such as Yes/No, On/Off, True/False.

let isActive = true;
let isAway = false;
Enter fullscreen mode Exit fullscreen mode

Boolean values also come as a result of comparisons:

let isGreater = 6 > 2;

alert(isGreater); // true (the comparison result is “yes”)
Enter fullscreen mode Exit fullscreen mode

Further reading

Want to learn more about JavaScript Data Types? Then check out this article on JavaScript Data Types – W3Schools

Thank you for reading and keep on coding.

Top comments (0)