JavaScript Basics #4: Data Types

JavaScript Basics #4: Data Types
Jan Zavrel
Jan Zavrel Follow June 19, 2021
Share:

In programming, we use the various kinds of data. To make a distinction, there are seven types of data in JavaScript. Except for the object data type that you already learned about (remember console?), the rest of them are so called primitives.

These are all the data types available in JavaScript:

  1. Number
  2. String
  3. Boolean
  4. Null
  5. Undefined
  6. Symbol
  7. Object

Number

This data type represents any kind of number, including numbers with decimals like 15.45.

String

String is a group of characters (letters, numbers, symbols) available on the keyboard. The important thing is that strings are always surrounded by quotes, preferably single quotes '....'. String is just a fancy word for a regular text.

Boolean

This data type represents logical state and has only two possible mutually exclusive values. It’s either true or false (notice it’s without quotes, so it’s not a string). You can think of Boolean as a switch that can be on or off.

Null

Null means an intentional absence of a value. It’s represented by the keyword null (again, without quotes as it’s not a string).

Undefined

Another data type that represents the absence of a value, but it has a different use than null. Undefined is represented by the keyword undefined (again, no quotes).

Symbol

Symbol is a new addition to JavaScript, useful in more complex programming. You don’t need to worry about it for now, just remember that it exists.

Object

Object represents a collection of related data and actions performed on such data. Unlike all the data type above, object is not a primitive, it’s a complex data type.

Before we move on, let’s practice the difference between strings and numbers. First, we will print a string surrounded by quotes. As you can see below, it’s a whole sentence composed of different words, spaces, and punctuation.

console.log('My name is Jan. My website is available at https://codewithjan.com.');

Next, we will print the number 40. Notice that in this case, we won’t use quotes.

console.log(40);

Follow me on Medium, Twitter, Facebook and YouTube.

Share:
Jan Zavrel
Written by

Jan Zavrel Follow

Developer, Author, Teacher, Evernote Certified Consultant.