Variables and Data in JavaScript

 Just like we follow some rules while speaking english (the grammar), we have some rules to follow while writing a javascript program. The set of these rules is called Syntax in javascript.


What is a Variable? 

A Variable is This is very a container that stores a value. similar to the containers used to store rice, water and oats (Treat this as an analogy!)

The value of a javascript variable can be changed during the execution of a program.

Var a = 7;. <-------Literal

Var a = 7;.    

"a" - Identifier

"=" - assignment operator


Rules for choosing variable names

→ letters, digits, underscores & $ sign allowed. 

→ Must begin with a $ _ , or a letter.

→ Java Script reserved words cannot be used as a variable name 

→ Harry & haRRy are different variable (case sensitive)


Var vs let in JavaScript 

1) Var is globally scoped while let & const are block scoped 

2) Var can be updated & re-declared within its scope 

3) let can be updated but not re-declared 

4) const can neither be updated nor be re-declared.

5) var variables are initialized with undefined whereas let and const variables are not initialized. 

6) const must be initialized during declaration unlike let and var.


Primitive Data Types & Objects 

Primitive data types are a set of basic data types in javascript 

Object is a non primitive datatype in javascript


These are the 7 primitive datatypes in javascript :

1) Null 
2) Number 
3) String 
4) Undefined 
5) Boolean 
6) Biglnt 
7) Symbol

Object
An object in JavaScript can be created as follows.

Const item = {
                           name : "Led Bulb",
                           price : "150"
                        }
Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.