x

We use the latest technologies to provide the best experience!

Please download a newer version of your browser. Click to close

Looking to get better at JavaScript?
Join us in the Academy and boost your learning curve!
visual overview of JavaScript Data types

What are the JavaScript Data types?

An overview of the 8 most important Data Types in JavaScript, why they are important and how to use them.
Karla E. Costa Silva
JavaScript Teacher
03 August 2020
If you just started programming, you probably already heard about JavaScript data types, maybe you are already familiar with strings, numbers and even objects or arrays. And that’s because data types are a very important concept in programming, the computer needs to know exactly what we mean, so it will be able to operate on the variables.In this article, I will show you some of the most common data types and we will discuss all of them in more detail. There are 8 basic data types in JavaScript: String, Number, BigInt, Boolean, Null, Undefined, Objects and Symbols. They are divided into two categories: primitive and non-primitive, only the Objects belong to the non-primitive category.
Strings in JavaScriptThe string data type represents text and, in JavaScript, a string must always be surrounded by quotes, you can use double quotes, single quotes or backticks, the backticks adds extra functionality to our string, and we can use it to display a variables' values.a piece of string data type in a coding terminalAs you see in the code snippet above, we can concatenate the strings or combine them inside the backticks quotes. Also, when displaying a variable, we always have to use ${} and put it inside the curly brackets.
Number and BigInt in JavaScriptThe number data type is used to represent positive or negative numbers with or without decimal place, and unlike some other programming languages, JavaScript does not define other types of number, like integers, short, long, etc. There are many operations for numbers: multiplication *, division /, addition +, subtraction -, and so on. Example of operations in JavaScriptBesides regular numbers, there are some “special numeric values” which also belong to this data type: Infinity, -Infinity and NaN. example of working with infinity in JavascriptThe BigInt type was recently added to JavaScript to represent integers of arbitrary length, because the number type cannot represent integer values larger than (253-1) or less than -(253-1) for negatives and sometimes we need really big numbers.example of the JavaScript bigInt data type in a terminal
Booleans in JavaScriptThe boolean type has only two values: true and false. It is commonly used to store values like yes (true) or no (false), on (true) or off (false). It's also very used in comparisons inside if/else statements, like you can see in the following example.example of Boolean data type in JavascriptUndefined and Null in JavaScriptWhen we declare a variable, but don't assign any value to it, we'll get the value of undefined. So, basically, a variable without a value, has the value undefined.example of undefined data type in JavaScriptThe null data type is supposed to mean "nothing", it’s a special value which represents “nothing”, “empty” or “value unknown”. You can also use null to empty an object, for example.example of null data type in JavaScriptThe types undefined and null are equal in value, but different in type, undefined is type undefined while null in an empty object.
The Objects and Symbols typeAll other types are called “primitive” because their values can contain only a single thing, objects are used to store collections of data and more complex entities.An object contains properties, defined as a key-value pair. A property key (name) is always a string, but the value can be any data type, like strings, numbers, booleans, or complex data types like arrays, functions and other objects.example of object data type JavaScriptThere are many other kinds of objects in JavaScript: Array, Date, Error and more. Here you can see an example of an array of objectsexample array of objects in JavascriptSymbols were introduced to JavaScript in ECMAScript 2015, they are often used to identify object properties, mostly to avoid name clashes between properties, since no symbol is equal to another or to add properties that the user cannot overwriteexample of symbol data type in javascriptI hope this post was clarifying and helped you learn a lot about JavaScript data types, to dive deeper in the subject you can always consult the JavaScript documentation. Got any questions, remarks or additions for us, please email to support@codaisseur.com and we will get back to you.

Interested in more?

Read more of our articles.