How to do it...

In this section, we will see how to use the most important JS features in React:

  1. let and const: The new way to declare variables in JavaScript is by using let or const. You can use let to declare variables that can change their value but in block scope. The difference between let and var is that let is a block scoped variable that cannot be global, and with var, you can declare a global variable, for example:
    var name = 'Carlos Santana';    let age = 30;    console.log(window.name); // Carlos Santana    console.log(window.age);  // undefined
  1. The best way to understand "block scope" is by declaring a for loop with var and let. First, let's use var and see its behavior:
    for (var i = 1 ; i <= 10; i++) {      console.log(i); // 1, 2, 3, ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.