Categories: JavaScript

What are JavaScript Variables?

Understanding JavaScript Variables
Variable are the JavaScript containers in which data in multiple form are stored, in another term they are just containers only. They are one of the fundamental core feature of JavaScript for their diverse use in the scripting respectively. They have some unique identifiers, types, rules, usage that we are going to study with this important topic one by one.

In the following example a, b and c are the variables with different values

var a = 2;
var b = 3;
var c = a + b;
Yes JavaScript Variable look simple and easy to begin with simple operators but their use and scope is huge with lot of complexities.

Identifiers for Variables in JavaScript

All JavaScript variable have unique set of rules or identifiers which must be followed to use them for getting specific results.

  • Var names can have letters(a-z), digits(0-9), underscores(_), and dollar signs($)
  • First character must be defined with a character only.($ and _ are also allowed)
  • They can hold all data types, perform operations, functions and more in multiple form and use them
  • Like any other language there are few JavaScript reserved words which cannot be used as name for variables
  • Javascript Variables are case sensitive i.e Small ‘a’ and Capital ‘A’ are two different variables completely.

How to Declare JavaScript Variables?

JavaScript Variables are declared within <Script> tag with Var word accompanied by their specific name. For e.g. we have named a Var with building but without any value thus technically undefined.

Var building;

So with value it has to be define i.e. in a specified way

building = "apartments"; 

or combine them together
var building = "apartments"; 
You can use declaring variable and its value separately or combined at your choice.

JavaScript Variable Examples


Redeclare

Multiple variable

Undefined

Arithmetic

JavaScript Variable Types

Based on the accessibility and scope JavaScript has two types.

  • Local Scope
  • Global Scope

JavaScript Global Variable

These variables are declared outside the function and have accessible anywhere inside within the script.


JavaScript Local Variable

Variables that are defined inside a function and are not accessible outside it are termed as Local Variables in JavaScript. A local variable is then only local scope and hence limited accessibility.


Rohan pathak

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

6 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

6 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

6 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

6 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

6 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

6 months ago