Data Types

In this lesson, we’ll cover the most important data types available in JavaScript.

Data Types #

JavaScript is a dynamic language, meaning that on the contrary to a static language, you don’t have to define the type of your variables when you define them.

Press + to interact
// is this a string or a number ?
var userID;
userID = 12; // now it's a number
console.log(typeof userID); // number
userID = 'user1' // now it's a string
console.log(typeof userID); // string

This may seem convenient at first, but it can be a cause of problems when working on bigger projects. At the end of this course, after you have mastered the basics of JavaScript, I’ll introduce you to TypeScript, which adds strong typing to JavaScript.

There are 7 data types in JavaScript : 6 primitives and the Object.

 

Primitives #

A primitive is simply data that is not an Object and doesn’t have methods.

They are:

  • string
  • number
  • boolean
  • null
  • undefined
  • symbol (the latest addition)

Let’s have a quick look at all of them, some of which you may already know if you have prior experience in programming.

string is used to represent text data, whether it’s a name, an address or a chapter of a book.

Press + to interact
let userName = "Alberto";
console.log(userName) // Alberto

number is used to represent numerical values. In JavaScript there is no specific type for Integers. ...

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy