The Basics of Variables in JavaScript: Types, Declarations, and Examples
Now, let’s begin with JavaScript. As I mentioned earlier about frontend development and JavaScript, I will not discuss it again.
The Basics of Variables in JavaScript: Types, Declarations, and Examples
Now, let’s begin with JavaScript. As I mentioned earlier about frontend development and JavaScript, I will not discuss it again.
Photo by Goran Ivos on Unsplash
What is a variable?
A variable stores data. If a person is a beginner, it will be difficult for them to understand what I am saying, so I appreciate examples to help them better understand. A variable is like a container where we store data. As everyone has seen, candy has a wrapper on it. In this scenario, the wrapper is a variable to store Candy data.

I have declared a variable total mark and assigned it a value of 100. We end each statement in JS with a semicolon(‘;’). We use camelcase to declare variables. The first letter is lowercase, and the next word begins with an uppercase.
Variable Declarations:
There are three ways of variable declaration 1. let: This is used to declare a variable when there is a chance to change the value of the variable For example, when you have to print a 1 to 10 count, you will use the let keyword for variable declaration. It will allow you to increment the value. let num=1; 2. var: This keyword is also used for variable declaration. But it is not recommended because when you declare a variable, it allows you to declare the variable again. For example, if you have created a variable personName, you will use it, and again, if you declare it after forgetting you have declared it before, then unnecessary work will happen. var personName=” David”; var personName=” Zara”; So this leads to unexpected behavior as personName would store “Zara” as ‘’Zara” and you will lose your previous name. While this scenario shows an error in const and let
3. const: This is useful when you know you do not need to change a variable value. For Example: const myName=” Jin”; The value of myName will be the same throughout the code.
메타데이터
- post_id
- 7d3bb3307b8f
- slug
- the-basics-of-variables-in-javascript-types-declarations-and-examples-7d3bb3307b8f
- url
- https://medium.com/coding-nexus/the-basics-of-variables-in-javascript-types-declarations-and-examples-7d3bb3307b8f
- canonical_url
- https://medium.com/coding-nexus/the-basics-of-variables-in-javascript-types-declarations-and-examples-7d3bb3307b8f
- author_url
- https://medium.com/@elevatexcareer
- status
- ok
- fetched_at
- 2026-07-11 02:02:54