JavaScript Learning Notes

Comprehensive guide to JavaScript fundamentals

Topics
Click on any topic to view detailed notes
Variables & Constants
Learn about const, let, var and their differences
JavaScript
// Variables and Constants in JavaScript

const accountId = 123312; // always use const as a constant
let accountEmail = "kachua@gmail.com"; // always use let as a variable  
var accountcity = "banglore"; // do not use var as it has scope problems
accountname = "kachua"; // bad way to declare variables

// Key Points:
// • const - cannot be reassigned, use for constants
// • let - block-scoped, preferred for variables
// • var - function-scoped, avoid using (scope issues)
// • Never declare without keyword (creates global variable)

console.table([accountId, accountEmail, accountcity, accountname]);

Key Takeaways

  • • Always use const for values that won't change
  • • Use let for variables that will change
  • • Avoid var due to scope issues
  • • Never declare variables without keywords (creates globals)