JavaScript Datatypes

Lesson 4: JavaScript Data types



We already know what data is. If you didn’t read, check here.

To store data we need data types. These are required by computer to differentiate data.

For instance we can perform mathematical operations such as addition, or division on numbers. But, we can’t do it with strings.

JavaScript provides eight different data types for you to work with. They are:

  • undefined: Here the value is undefined.
    • car = undefined;
  • null : It means nothing. You can set the value of a variable to null to empty it. Though, it’s practically an object. That’s for geekers.
    • car = null
  • boolean: Set’s the value to true or false
    • carGPS = false
  • string: Used to store strings
    • var carType = "SUV"
  • symbol: Symbols are immutable (cannot be changed) and are unique. These are new. More on these later.
    • let sym2 = Symbol('foo')
  • bigint:  Represent integers with arbitrary precision. Store big values easily.
    • var bigint = 1234567890123456789012345678901234567890n;
  • number: Used to store numbers with or without decimals.
    • var carPrice = 25000;
  • object: These are name value pairs.
    • var cars = {name:"BMW",type:"SUV", modle:2015};
      

Geeky stuff:

Arrays are just regular objects. Thank me for clearing this up for you. These are regular objects in JavaScript.

Post a Comment

0 Comments

React