Search⌘ K
AI Features

Data Types

Explore JavaScript data types by learning the six primitives and the object type, understand how to create and manipulate objects and arrays, and grasp key concepts like copying by reference and using dot and bracket notation for properties.

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.

Node.js
// 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.

Javascript (babel-node)
let userName = "Alberto";
console.log(userName) // Alberto

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

Javascript (babel-node)
let age = 25;

boolean is used to represent a value that is either true or false.

Javascript (babel-node)
let married = false;

null represents ...