Discussion: On or Off?
Execute the code to understand the output and gain insights into using an object as a compact alternative to if…else statements for mapping values.
We'll cover the following...
We'll cover the following...
Verifying the output
Now, it’s time to execute the code and observe the output.
Press + to interact
Javascript (babel-node-es2024)
let response = "on",state = {on: 1, off: 0}[response]console.log(state);
The trusty if
…else
Suppose we have a light switch that can be turned on or off. We receive a ...