Predict the output of the code snippet below:
“155cm” is logged to the console. Let’s take a look at what’s happening. On line 6 when the constructor function is called, the value of 165cm is assigned to the property of height. Even though 165 is assigned, the return statement is ultimately what dictates the returned value when height is accessed. Think of the return statement as an override, as it is not actually changing the value of height, it is simply reporting the value the programmer tells it to.
What will be logged to the console after running the attached code snippet?
An error will be thrown. An imported module is read-only, so we cannot modify tracker.js from script.js. Only the exporting module, in this case tracker.js can modify this value.
Predict the output of the following code:
‘x’ is logged to the console. Not sure how let happened? Let’s think of another example: