Everything you need to know about JavaScript variables!😁

Everything you need to know about JavaScript variables!😁

everything you need to know about JavaScript variables in a nutshell

Hi there, Know that I'm filled with joy having you today! Your presence brings warmth to my heart💓. I will be explaining everything you need to know about JavaScript variable declarators

so let's dive in...

What are Variables?

In JavaScript, variables are used to hold a value. javascript variables can hold any value.

We use either the var, let, or const keywords to declare variables.

for example,

var x;
let y;
const z;

Here, x, y, and z are variables.

JavaScript variable is also simply known as the name of the storage location. That is javascript variable points to a location.

There are two types of variables in JavaScript:

local variable and global variable.

What are JavaScript variable declarators?

From the word "declaration", which means the act of making an official statement about something,

for example

the act of declaring something

"a declaration of love"

Javascript declarators are a statement that declares a variable. Creating a variable in JavaScript is called "declaring" a variable.

examples of javascript variable declarators include:

var keyword variable declarator

let keyword variable declarator

const keyword variable declarator

Declaring a JavaScript Variable

Ways to Declare a Variable in JavaScript are by

  • Using var

  • Using let

  • Using const

  • Using nothing

You declare a JavaScript variable with the var, the let, and the const keyword:

var myName;

//or

let myName;

After the declaration, the variable has no value (technically it is undefined).

To assign a value to the variable, use the equal sign which brings us to

The Assignment Operator

In JavaScript, the equal sign (=) is an "assignment" operator, not an "equal to" operator.

Note:

This is different from algebra.

The "equal to" operator is written like == in JavaScript.

After the declaration, the variable has no value (technically it is undefined).

To assign a value to the variable, use the equal sign

myName = "Abraham";

You can also assign a value to the variable when you declare it:

let myName = "Abraham";

In the example, we created a variable called myName and assign the value "Abraham" to it.

what are JavaScript Identifiers?

There are some rules while declaring a JavaScript variable (also known as identifiers). The name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.

The general rules for constructing names for variables (unique identifiers) are:

  • Names can contain letters, digits, underscores, and dollar signs.

  • Names must begin with a letter.

  • Names can also begin with $ and _

  • Names are case-sensitive (y and Y are different variables).

  • Reserved words (like JavaScript keywords) cannot be used as names.

Hope you enjoyed your reading, Stay tuned! Peace out ✌😎