Java Script General Information
Tags: javascript, programming, webdev, beginners
Published: 2022-11-09 13:11:22

## JavaScript Variables
Variables serve as data storage devices.

Here are two illustrations:

1) An online store - the data may include information about products being sold and a shopping cart.
2) A chat program; data could include users, messages, and much more.

Use the let keyword in JavaScript to define a variable. We can also substitute the term "var" for the word "let" in older scripts. The word "var" is nearly identical to the word "let." A variable is also declared, albeit in a somewhat different, "classic" manner.
Let and var have a few minor differences, but we'll mostly use var.

## Code explanation of Var

**_var name = 'Argishti';_**

Here, the information "Argishti" is contained in the variable name.

**_console.log('Argishti');_**

You can refer to such a variable in your code once you have one in JavaScript. The following is an example of how you can print something with JavaScript.

**_var name = 'Argishti';

console.log(name);
_**

This will give the name Argishti as output in console.

Instead of using the information explicitly, you can put the information into a variable, and use this variable instead the implicit way.

## What is Scope in Java

The term "scope" in JavaScript refers to the context of the currently running code, which establishes the variables' availability to JavaScript. Local and global scope are the two types: Those stated outside of a block are considered global variables. Local variables are those that have been declared within a block.

## Global Scope

The global scope is the outermost scope in JavaScript. Any variable declared in global scope can be accessed anywhere.

\\ script.js

let message = "hello"

A variabe declared in local scope can only be accessed inside that local scope. That includes any other local scopes defined inside it.

Scopes are categorized into 3 types:

1.Block scope

2.Function scope

3.Module scope

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rxansvd1bshh2qzrdt1.png)

## **_Block scope_**

In JavaScript, a code block is defined using curly braces {}. Any variable declared inside is in block scope. This applies to if, for, and while statements.

## **_Function scope_**
Any variable declared inside a function is in function scope. It works for var, let, and const.
 
**_

## Module scope
_**
With the introduction of ES6, modules are a reality. Any variable defined inside a module is within the module scope and cannot be used elsewhere.

## Deep in Variables

Now that we know what scope is and also covered var, It is a god time to cover other type ov variables as well.

**LET**

A block scoped variable in JavaScript is declared with the let keyword. Variables defined using the let keyword are block scoped in contrast to those declared using the var keyword, which is often used to declare a variable in JavaScript and is handled as a standard variable.

**Constant**

Like variables declared with the let keyword, constants are block-scoped. A constant's value cannot be altered via reassignment. The attributes or items of a constant, on the other hand, can be changed or deleted if it is an object or array.