DEV Community

Cover image for Fundamentals of let, const, var πŸš€
khalid
khalid

Posted on

2

Fundamentals of let, const, var πŸš€

Variables: Variables in JavaScript are containers for storing data. JavaScript allows the usage of variables in the following three ways:

var:

var is the most commonly used variable in JavaScript. It can be initialized to a value, redeclared and its value can be reassigned, but only inside the context of a function. It can be function scoped or globally scoped.

using var

let:

let in JavaScript is similar to var only difference lies in the scope. var is function scoped, let is block scoped. It cannot be redeclared but can be reassigned a value.

Using let

const:

const in JavaScript is used to declare a fixed value that cannot be changed over time once declared. They can neither be redeclared nor be reassigned. They cannot be hoisted either.

Using const

πŸ“’Connect with me on LinkedInπŸš€

Top comments (0)

Need a better mental model for async/await?

Check out this classic DEV post on the subject.

β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

async await

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay