Variables in JavaScript

JS variables are used to store data values. But unlike any other language, the datatypes of that variable are not declared first like in C++. JavaScript has dynamic types. This means that the same variable can be used to hold different data types,

v…


This content originally appeared on DEV Community and was authored by Sanskrati Jain

JS variables are used to store data values. But unlike any other language, the datatypes of that variable are not declared first like in C++. JavaScript has dynamic types. This means that the same variable can be used to hold different data types,

  1. var, let, and const:

To declare variables we use var, let, and const.
var and let are very similar except in block scope which is discussed in the difference between var and let.
cont is the same as let but used only for constants.

Alt Text

  1. Difference Between var and let: The main difference between var and let is that scope of var is global while that of let is limited to block. This means if I declare a variable using var, it can be excessed anywhere except in the case of a function. This can be a problem if we use it in loops for example.

Alt Text

  1. Properties of const : People usually misunderstood the cont. It does not define a constant value. It defines a constant reference to a value, which means we can actually change the properties of a constant object or the element of a constant array. It is just you can reassign a value.

Alt Text


This content originally appeared on DEV Community and was authored by Sanskrati Jain


Print Share Comment Cite Upload Translate Updates
APA

Sanskrati Jain | Sciencx (2021-05-17T17:46:24+00:00) Variables in JavaScript. Retrieved from https://www.scien.cx/2021/05/17/variables-in-javascript-2/

MLA
" » Variables in JavaScript." Sanskrati Jain | Sciencx - Monday May 17, 2021, https://www.scien.cx/2021/05/17/variables-in-javascript-2/
HARVARD
Sanskrati Jain | Sciencx Monday May 17, 2021 » Variables in JavaScript., viewed ,<https://www.scien.cx/2021/05/17/variables-in-javascript-2/>
VANCOUVER
Sanskrati Jain | Sciencx - » Variables in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/17/variables-in-javascript-2/
CHICAGO
" » Variables in JavaScript." Sanskrati Jain | Sciencx - Accessed . https://www.scien.cx/2021/05/17/variables-in-javascript-2/
IEEE
" » Variables in JavaScript." Sanskrati Jain | Sciencx [Online]. Available: https://www.scien.cx/2021/05/17/variables-in-javascript-2/. [Accessed: ]
rf:citation
» Variables in JavaScript | Sanskrati Jain | Sciencx | https://www.scien.cx/2021/05/17/variables-in-javascript-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.