Javascript Variables and Data Types : Javascript Essentials

Variables are symbolic names for values. Variables are used to store dynamic values in it. The names of variables, or identifiers, must follow certain rules.

A JavaScript variable name must start with a letter, underscore (_); subsequent characters can also be digits (0-9). As JavaScript is case sensitive, letters include the characters A through Z (uppercase) and the characters a through z(lowercase).

Variables in JavaScript should be defined with the var/let keyword. If you declare a variable without assigning a value to it, its type is undefined by default.

let is used for block level scope variable declarations.

JavaScript supports the standard variations of Data types:

  1. Number
  2. String
  3. Boolean
  4. Symbol (new in ECMAScript 6)
  5. Object:
    1. Function
    2. Array
    3. Date
    4. RegExp
  6.  Null
  7. Undefined
    A Number type is a combination both integer and floating, which can be decide automatically on assigning a value to variable. For example see below.

    var num = 22;
Above declaration will be integer.

    var pival = 3.14;
Above pival is a floating variable.


In JavaScript, strings are a sequence of Unicode characters (each character takes 16 bits). Each character in the string can be accessed by its index. The first character index is zero. Strings can be enclosed in either double quotation marks ("") or single quotation marks ('').

     var name = "Mr. X";

Above is the example to create string variable.

In javascript string also contains a wrapper object which is String

    var name = new String("Mr. X");

String Object is having different methods associated with it. Few list is as follows:

  1. length
  2. charAt(index)
  3. indexOf(character)
  4. lastIndexOf(character)
  5. includes(character)
We'll discuss details about String object in another article.


    JavaScript Boolean data type is represented by true and false keywords. Below values represent true and false.
 False, 0, the empty string (""), NaN, null, and undefined are represented as false.
Except the above values everything is true.


Popular posts from this blog

Reasoning Syllolism Quiz

Reasoning Puzzles for IBPS PO