Introduction
This article will cover the basic concepts of JavaScript, the most important being variables and data types.
Variable in JavaScript
A Variable is an identifier or a name used to refer to a value. It is media that stores the information referenced and manipulated in a computer program. Using the key of a variable in JavaScript “var”, the extension is important (.js).
Syntax
Note. In the example, the number 10 is assigned to “a”. Use only the special characters (__) underscore and ($) symbol, don't use other special characters like @, *, %, or #. JavaScript is case-sensitive.
In this example, the variable name ‘a’ is uppercase.
Error
Example 1
Output
Example 2
Output
There are two types of Variables
- Local Variable
- Global Variable
JavaScript Local Variable
The local variable is a variable in which a variable can be declared within the function, and it can be used only inside that function. So, variables with the same name can be used in different functions.
Example
//local Variable
Output
JavaScript Global Variable
The global variable is a variable in which variables can be defined outside the function. So, variables with the same name cannot be used in different functions.
Example
//Global Variable
Output
Summary
In this article, we looked at how to declare a variable in JavaScript. In my next article, we will learn the data types in JavaScript. I hope this article is very useful for you.
Reference
Thanks for reading.