·Sep 16, 2020·
1 min read
Play this article
Let's start with Variables.
A Variable is a container that can hold a certain value, like in Maths we have variable
y are variables that can hold a number.
In JS, we define a variable using
var a = 2; // here "a" holds the value 2
Here's an another example:
var b = 6; var c = 4; console.log(b+c); // Now b = 4 and c = 6, so output will b +c i.e 10
Variables can hold various Data Types, which we'll learn in futher lessons.
var greet = "Hey There!"; // greet holds a String data type. var age = 21; // age holds an integer data type.
NOTE: If you declare a variable with
var keyword initially and the re-assign a different value to it, the previous value gets overwritten.
var name = "Elon Musk" console.log(name); // Elon Musk gets logged. var name = "Tesla" console.log(name); // name is now Tesla, not Elon Musk
If you have any reviews about this series or my way of explanation, then please let me know 🙂.