Hey guys I am back!
Let's start with the difference between Value and variable
Value is a piece of data while the variable is a container that can hold a value and it can vary many times.
For eg: console. log(12) // Here 12 is printed in the console which is the value.
let firstName = 'Aayush' ; Here firstName is a variable because it can store the value Aayush and as discussed above firstName can be changed to only name.
Difference between let, const, var
- let, is used to assign the variable which can be changed later on
for eg: let myfirstJob = 'Teacher' if you remember your first job was not as a teacher but assistant teacher then you can simply write myfirstJob = 'assistant teacher' and you don't need to use the let keyword again because you already assigned it once. Note:
- a) let variable can be assigned empty and later used
- b) you can change the value of the variable anytime
c) It is only accessed via its scope here, myfirstJob is only accessed inside this myFunction
var, it's the same as let all the functions are also the same but the only difference is var element can be accessed outside the scope so I recommend using let instead of var.
const, It is another very important assignment operator in Javascript. Note:
- a) You cannot leave the const variable empty it will print an error
- b) once the value to the variable is assigned it cannot be changed
- c) You cannot assign the same variable to another value meaning it can be only used once
Thankyou. see you in the next blog post if you have any questions please don't forget to comment.