JS - Different data types of variable

0 votes
170 views
added Jul 23, 2018 in Javascript by LC Marshal Captain (25,790 points)
  1. String - A sequence of text known as a string. To signify that the variable is a string, you should enclose it in quote marks. 
    var myVariable = 'Bob';
  2. Number - A number. Numbers don’t have quotes around them. 

    var myVariable = 10;
  3. Boolean  - A True/False value. The words true and false are special keywords in JS, and don’t need quotes. 

    var myVariable = true //or false
  4. Array - A structure that allows you to store multiple values in one single reference. 

    var myVariable = [1,'Bob','Steve',10];

    Refer to each member of the array like this:

    myVariable[0], myVariable[1], etc.
  5. Object  - Basically, anything. Everything in JavaScript is an object, and can be stored in a variable. Keep this in mind as you learn. 

    var myVariable = document.querySelector('h1');
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...