Data Types In Javascript

Table of contents

No heading

No headings in the article.

A major leap stone to understanding javascript and eventually other frameworks is by understanding the basics which is the data types. Data types in javascript are classifed into two groups which are

  1. PRIMITIVE TYPES
  2. REFERENCE TYPES

Primitive types are data types that have no methods or properties. They are data types that cannot be changed. They are largely classified as immutable types which means they cannot be changed. Primitive types include

  1. Strings
  2. Numbers
  3. Null
  4. Undefined
  5. Boolean
  6. Symbols

The symbol being the latest addition to the pack. The string can be dicey because we perform some manipulation on them like split method which converts it to an array for further manipulation but these methods are not actually performed on the string but the reference to the string. I will show you.

let a='mango'; a.split().slice(); //['m','a','n','g','o'] --expected output console.log(a) //'mango' --expected output

Those methods were not actually performed on the string but a reference to the string. Strings are immutable properties. For you to change them, you have to reassign them. This feature makes them comparable which means string a is always equal to string a. All primitive types are comparable.

let foo=false; let boo=false; console.log(foo===boo) //true

##REFERENCE TYPES These are data types that can be muted, operated upon, manipulated and they also serve as storage containers too. The three types are

  1. Object
  2. Arrays
  3. Functions

These types are defined as reference types and they are mutable properties which means that they can be operated upon. No two objects are the same except if they are directly referenced to each other

let c={name:'cat'} let d={name:'cat'} console.log(c===d) //false

However, if we reference an object to a variable, it equates to true

let m=c console.log(m===c) //true

Understanding these concepts are vital in understanding javascript and frameworks too especially react. For instance, react expects you to treat objects and arrays as immutable properties. I would be talking about different types in subsequent posts.