Javascript

Photo by RetroSupply on Unsplash

Javascript

''Value and Variable, and let const, var"

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

  1. 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

Screen Shot 2022-10-30 at 1.15.21 pm.png

  • b) you can change the value of the variable anytime

Screen Shot 2022-10-30 at 1.16.05 pm.png

  • c) It is only accessed via its scope Screen Shot 2022-10-30 at 1.17.08 pm.png 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

Screen Shot 2022-10-30 at 1.20.02 pm.png

  • b) once the value to the variable is assigned it cannot be changed

Screen Shot 2022-10-30 at 1.21.28 pm.png

Screen Shot 2022-10-30 at 1.21.48 pm.png

  • 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.