This content originally appeared on DEV Community and was authored by Sooraj S
What's the output ?
function getAge() {
'use strict';
age = 21;
console.log(age);
}
getAge();
- A:
21
- B:
undefined
- C:
ReferenceError
- D:
TypeError
Answer: C
With "use strict"
, you can make sure that you don't accidentally declare global variables. We never declared the variable age
, and since we use "use strict"
, it will throw a reference error. If we didn't use "use strict"
, it would have worked, since the property age
would have gotten added to the global object.
This content originally appeared on DEV Community and was authored by Sooraj S
Sooraj S | Sciencx (2021-07-19T13:58:32+00:00) JavaScript question #Day 9. Retrieved from https://www.scien.cx/2021/07/19/javascript-question-day-9/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.