Explain Datatypes and Variables in Javascript?

JavaScript is a dynamically typed (also called loosely typed) scripting language. That is, in JavaScript variables can receive different data types over time. Datatypes are basically typed data that can be used and manipulated in a program.

The latest ECMAScript(ES6) standard defines seven data types: Out of which six data types are Primitive(predefined).

  • Numbers: 5, 6.5, 7 etc.
  • String: “Hello Board Infinity” etc.
  • Boolean: Represent a logical entity and can have two values: true or false.
  • Null: This type has only one value : null.
  • Undefined: A variable that has not been assigned a value is undefined.
  • Object: It is the most important data-type and forms the building blocks for modern JavaScript. We will learn about these data types in detail in further articles.

Variables in JavaScript:

Variables in JavaScript are containers that hold reusable data. It is the basic unit of storage in a program.

  • The value stored in a variable can be changed during program execution.
  • A variable is only a name given to a memory location, all the operations done on the variable effects that memory location.
  • In JavaScript, all the variables must be declared before they can be used.

The var\_name is the name of the variable which should be defined by the user and should be unique. These types of names are also known as identifiers.