Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Initializing Variables in Javascript

Types of Initializing Variable

var roll;
roll = 101; var roll = 101; roll = 101;

var name;
name = “devopsschool.com”; var name = “devopsschool.com”; name = “devopsschool.com”;

price = 125.36;
Initializing Variable var price = 125.36; price = 125.36;

Whatever happens, is optional so only you roll = 101; can also write. Var is not necessary but if you use this is a good practice.

Rules of Initializing Variable

  • Strings are written inside double or single quotes.
  • Numbers are written without quotes.
  • If you put a number in quotes, it will be treated as a text string

Initializing Variable

var ans = true;
var result = false;

Initializing Variable example

var x = 10, y = 20, c = 30;
var fname = “DevOps”, lname = “School”;
var name = “DevOpsSchool”, roll = 101;
var name = “DevOpsSchool”,
roll = 101,
address = “Steel City”;
Tagged : / /

Variables in Javascript with Rules

Variables

A variable is an identifier or a name which is used to refer a value. A variable is written with a combination of letters, numbers and special characters _ (underscore) and $ (dollar) with the first letter being an alphabet.

Ex-

c, fact, b33, total_amount etc.

Rules

• Variable can contain combination of letters, digits, underscores ( _ ), and
dollar signs ( $ ).
• Must begin with a letter A-Z or a-z or underscore or dollar sign
• A variable name cannot start with a number
• Must not contain any space characters
• JavaScript is case-sensitive
• Can‟t use reserved keywords

Tagged : / / / /