Intro ES6

ECMASCRIPT - for JavaScript standardization

The European Computer Manufacturers Association (ECMA)

Use Cases

ES6 Variable

Interview

  • In programming, a variable is a named container that stores data.
  • It helps reuse and manipulation during program execution.
  • For example: let age = 25; stores the value 25 in a variable called age.

Syntax
var snacks = "Milk Bikis";

👉 Variable Type → var
👉 Variable Name → snacks
👉 Value → "Milk Bikis"



Variable Naming Conventions

JavaScript is Dynamically Typed

Scope in JavaScript
Types of Scope
  1. Global Scope
  2. Local Scope

Global Scope

Local Scope

👉 Function Scope → function உள்ளே.
👉 Block Scope → for loop, while loop உள்ளே.

Interview

  • Global Scope → Variable can be accessed anywhere in the program.
    Example: var x = 10; (x is available everywhere).

  • Local Scope → Variable can be accessed only inside a function or block.
    Example: let y = 20; inside a function (y can’t be used outside).


var Keyword Drawbacks

let Keyword

👉 Local Scope

  1. Function Scope
  2. Block Scope

const Keyword

👉 Example in Array:
const array-க்குள் values push செய்யலாம், ஆனால் datatype & variable definition மாற்ற முடியாது.

Important Note
  1. If you didn't define them, they would be assigned to the global object
  2. If you use for var outside of a function, its belongs to the global scope
  3. If you use var inside of a function, its belongs to that function
  4. If use var inside of a block, i.e. a for loop, that variable is still available outside of that block.
Feature var let const
Scope Function scope Block scope Block scope
Re-declare Allowed Not allowed Not allowed
Re-assign Allowed Allowed Not allowed
Hoisting Hoisted (undefined) Hoisted (not initialized) Hoisted (not initialized)
Example var a = 5; let b = 10; const c = 15;