Variable and Datatype in js:

Variables:

Hey, let us begin our JAVASCRIPT journey. The concept of variable is same in js with the other language.

Variables are containers for storing information that can be referenced and manipulated within a program. In JAVASCRIPT variable can be declared using "let", "var", "const" keywords.

Initially "var" was the primary keyword to declare variable. Variables declared with "var" are functionally scoped or globally scoped but not block scoped (meaning they are not confined to the block in which they are declared).

On the other hand "let" allows to declare variable which are block scoped . Variables declared with "let" are mutable that mean that value can be changed further if needed. It was introduced in ES6.

"const" was also assigned in ES6. The variable declared with "const" are block sopped and immutable, the assigned values can't be changed further.

Here's an example of variable declaration and assignment in JavaScript:

var x = 10;
let x = 8;
const pi = 3.14;

Datatypes:

Datatype just defines the value that a variable can hold. In javascript datatype can be classified in two ways primitive and non primitive datatype.

primitive datatype:

primitive datatype are immutable. It directly stored in memory and accessed by value. There are 6 primitive datatype.

  • Number: Represents numeric values, both integers and floating-point numbers.

  • String: Represents textual data, enclosed in single ('') or double ("") quotes.

  • Boolean: Represents a logical value, either "true " or "false".

  • Undefined: Represents a variable that has been declared but not assigned a value.

  • Null: Represents the intentional absence of any value.

  • Symbol (ES6+): Represents a unique identifier. Symbols are often used as property keys in objects to avoid naming conflicts.

Non-primitive datatype:

non primitive datatype are mutable that means it can be changed further. They are stored references(or addresses) of the actual data and these are accessed with the reference. Non primitive datatype includes

"object ", "array", "function", "date" etc.

// Primitive data types
let numberVar = 50;          
let stringVar = "Hello";   
let booleanVar = true;         
let undefinedVar = undefined;
let nullVar = null;          
let symbolVar = Symbol("foo"); 

// non primitive data types
let objectVar = {             
    key: "value",
    pass:"1567"
};
let array = [1, 2, 3]; 
let functionVar = function() { 
    console.log("Function");
};
let dateVar = new Date();

that are the basic syntax of assigning different datatypes in javascript. we will discuss about each datatype in next blog. Till then keep learning.