This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Khalil Dev
What is variable in programming language?
A variable is a named storage location that holds a value. Variables are used to store data values that can be used later in your code. The value of a variable can be changed, as well as its data type, throughout the execution of a program.
How to create variable in JavaScript?
To declare a variable in JavaScript, you use the var
, let
, or const
keywords, followed by the variable name. Let's declare a few variable.
Variable declared using var
The var
keyword is used to declare a variable with function scope, which means that the variable is accessible within the entire function where it was declared.
Variable declared using let
The let keyword is used to declare a variable with block scope, which means that the variable is accessible only within the block in which it was declared.
Variable declared using const
The const keyword is used to declare a constant, which is a variable whose value cannot be changed.
How to name a variable?
It's good practice to use descriptive names for your variables to make your code more readable and easier to maintain. Avoid using reserved words as variable names, and use camelCase or snake_case to separate words in your variable names
Summary
Variable is used to store data. In JavaScript, a variable is declared using var
, let
and const
. It's best practice to give descriptive name to variable.
Thanks for reading.
Comment your thoughts and share if this can help others.
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Khalil Dev
Khalil Dev | Sciencx (2023-02-14T03:32:45+00:00) JavaScript Variable. Retrieved from https://www.scien.cx/2023/02/14/javascript-variable/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.