Variabls

Estimated reading: 1 minute 103 views

var

Syntax
				
					 var variableName = value;
				
			

Declares a variable that can be globally or locally scoped. In modern JavaScript, let and const are preferred over var due to better scoping rules.

let

Syntax:
				
					let variableName = value;
				
			

Declares a block-scoped variable that can be reassigned. It's preferred over var for its stricter scoping rules.

const

Syntax:
				
					const variableName = value;
				
			

Declares a block-scoped variable that cannot be reassigned. However, the value of a const variable which is an object or array can be mutated.

Additional Notes:

Use let when you expect the variable's value to change over time. Use const when the variable's value will remain constant throughout its lifecycle. Avoid using var due to its global or function-level scope, which can lead to unexpected behavior and bugs.

Share this Doc

Variabls

Or copy link