const { log } = console;constarray= [1,2,3];conststudents= ['Joe','Jane','Jack'];// ⭐️ for-in loop// ╭───╮ <------------------------- this is OK ✅for (constindexin students) {// this `const` behaves like://// // inside block scope// const index = <next index in students>//log(`${index}: ${students[index]}`);}// ⭐️ for-of loop// ╭───╮ <------------------------- this is OK ✅for (constvalueof array) {// this `const` behaves like://// // inside block scope// const value = <next value of array>//log(value);}// ⭐️ classic for-loop❗//// but this `const` behaves like: //// // in its own scope❗ (like function name scope)// // (inside for-loop but outside block scope)// // (between outer scope and inner block scope)//// const i = 0; // ⭐️ reassignment will fail❗//// ╭─ for-loop init scope ─╮// ╭───╮ <------------------------- this is NOT OK ❌for (consti=0; i <3; i++) {// ^^^// TypeError after the first iteration❗// (⛔ TypeError: Assignment to constant variable)log(i);}// output// ---------------------// 0: Joe// 1: Jane// 2: Jack// 1// 2// 3// 0 <----- ⭐️ first iteration (then fails)// ⛔ TypeError: Assignment to constant variable.