Variables

_Khojiakbar_ - May 29 - - Dev Community
  • Variables in JavaScript are containers for storing data values.
  • They are declared using the var, let, or const keywords.
  • Variables declared with var have function scope or global scope, while those declared with let or const have block scope.
  • It's recommended to use let or const for variable declarations to avoid issues related to scope and hoisting.
// Variable declaration with var (function-scoped)
var firstName = "John";
console.log(firstName); // Output: John

// Variable declaration with let (block-scoped)
let lastName = "Doe";
console.log(lastName); // Output: Doe

// Variable declaration with const (block-scoped constant)
const age = 30;
console.log(age); // Output: 30
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .