Knowee
Questions
Features
Study Tools

What will the below statements print on the console?"use strict"function abc() {console.log(this);}abc();

Question

What will the below statements print on the console?

"use strict";
function abc() {
    console.log(this);
}
abc();
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the code will be undefined.

Here's the step by step explanation:

  1. "use strict" is a directive introduced in ECMAScript 5. It helps in catching common coding mistakes and "unsafe" actions such as using undeclared variables. When we use "use strict", the value of this in a function is undefined if the function is called in the global context.

  2. The function abc() is defined, which logs the value of this to the console.

  3. The function abc() is called in the global context.

  4. Since we are in strict mode and the function is called in the global context, the value of this inside the function is undefined.

  5. Therefore, undefined is logged to the console.

This problem has been solved

Similar Questions

What is the output of following code?var a = 10;function test() { a = 20;}test();console.log(a);Options: Pick one correct answer from below1020

What is the output of this code?const a = 12;function myFunction(a) { console.log(a);}myFunction(89);112289

What is the output of this code?function myFunction(a) { console.log(a + b);}const b = 79;myFunction(10);

Which statement invokes the function? Function definition Function call Function header All

How do Javascript primitive/object types passed in functions? By Value By Reference None of the above Both A and B

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.