Understanding Variables and Data Types in JavaScript

On the Internet or Web Everthing is DATA
Variable are the containers for the storing the data , It could be text, number, or any other information about anything. For using of the data we store in container. Insteand of updating the details everytime or everywhere, we will use that container name at everyplaces so that if we need to update then we just update once. like
var name = "hello world";
// name is the container and hello World is the value/data
lets discuss about container, var is not the only way to assign the container, we have let and const which can also assign the container to store the values/data like:
var name = "hello world";
let age = 28;
const isStudent = true;
Key Differnces of var, let and const
| Features | var | let | const |
|---|---|---|---|
| Scope | Function | Block | Block |
| Hoisting | Hoisted Initalized with undefined |
Hoistedtemporal dead zone |
Hoistedtemporal dead zone |
| Re-declaration | Allowed | Not Allowed in same Scope | Not Allowed in same Scope |
| Re-assignment | Allowed | Allowed | Not allowed |
| Global Assignment | Yes (window.varName) | No | No |
| Best Use | Avoid Using(old method) | When value may update | when value not to be updated |
Data/Values could be in multiple types...
Yes also we have multiple types of data. Primitive data types likes: text, number, truthy and so on...
let name = "hello JD" // 'String' for text or any other information
let age = 32 // 'number' can be data to be stored
let isWorking = true // 'boolean' is also data to be stored
let nothing = null // 'null' blank for now filled in the future
let notDefined = undefined // 'undefined' shows its not defined at
Basic for now for better understanding...
Scope
Scope is the area in where the can the access the container to get the values.
yes, we can control the container availability to be accessed
var gVar = "I am global" // called 'global scoped'
let gLet = "I am global" // can be accessed at everywhere
const gConst = "I am global"// till this file available
function outer(){ // just remember this bracket {function Scoped}
var oVar = "I am outer (var)" // can be accessed
let oLet = "I am outer (let)" // only inside the brackets
const oConst = "I am outer (const)" // not accesble outside
if(true){ // Again Brackets for area {block scoped}
var bVar = "I am block (var)"
let bLet = "I am block (let)"
const bConst = "I am block (const)"
}
}
Summary
As we understaind about In the web world every thing is data, so we use container (var,let,coist) to store. so the we have value at one place and use container name to avoid the rework at the time of value updation. Also we have some differences in between them (re-check table). And also we have multiple types of data/values to store basics for now. Scope (area of availabilty) for the container.
use
letif value updatesuse
constif value is fixedvaravoid using for future code.


