(click anywhere to close)

[JavaScript] Data Types

category: Website | course: JavaScript | difficulty:

At its core, a script manipulates data. It could for example calculate the sum of numbers a user provides, or generate a welcome message with a username when somebody logs in to his or her account. In order to do this, multiple basic data types are available, which are (in no particular order):

  • Number
  • String
  • Boolean
  • null
  • undefined
  • Object

All of these, except for the Object, are called primitives. Some more data types exist, but those are simply variations on these.

In this section I’ll only discuss how to input literals, which are just the literal fixed values and not results of a computation or links to another value. Those are discussed in great detail in their own respective chapters.


As expected, the Number data type holds any number. There are three ways to input them:

  • Integers: for round numbers
    • Written just like you normally would, for example: 4, 10, -40
  • Floating Point: for decimal numbers
    • Also like usual, but the comma must be a dot, for example: 4.3, 10.256
  • Scientific Notation: for extremely large or small numbers
    • Written in e-notation, for example: 123e5 = 123 * 105 = 12 300 000
100 = 100.000 = 1e2
0.005 = 5e-3


Strings represent text. They are created by enclosing the text within single or double quotes.

"I am a string";
'So am I';
//Do not use different quotes for start and end!
"I give an error';


A Boolean can only be either true or false. Their notation is exactly as you would expect; just the word itself.


null & undefined

Both values seem to do exactly the same – represent an empty value – but they are actually quite different.

The null word is a value that means “no specific value”. For example, you can’t remove a variable, so if you want to remove its value you can set the variable to be null.

The undefined word is not a value, which means it goes even further than null and just represents nothing. For example, accessing something non-existent, returns undefined.



An Object is an unordered collection of properties. This basically means that you can define a certain Object, then create a new instance of it, and it will automatically have all of these values and methods. It makes everything easier and faster. They are very important, and therefore discussed in their own chapters. The properties of an Object are accessed using the dot notation.


Methods & Arguments

Everything in JavaScript, except for the primitives, is an Object. Most of these have their own functions you can call on them. For example, the Math object has the function Math.random() to get a random number. Throughout the course I will call these functions methods, also to distinguish them from global functions you will learn to create yourself. Because even het JavaScript root – the container of all things – is an Object, constructs that don’t need anything prefixed, like parseInt(), are also called methods. So, whenever I introduce a new standard method, think of it as being a piece of code you can always call on a certain Object (that JavaScript automatically creates and maintains for you).

Sometimes, the object has certain values between the parentheses, for example Math.sin(x). These values are called arguments or parameters. Think of them like the value x you learned to put into a mathematical function at high school.

Because of this, JavaScript is called an Object-Oriented Programming Language (OOP), and you’ll learn to see and use everything as an object with a certain purpose.

Do you like my tutorials?
To keep this site running, donate some motivational food!
Chocolate Milk