Question #45

Author: admin
tags: JavaScript  
const x = 5;

let obj;

function showX() { console.log(x); }

function test() {
  const x = 6;
  obj = {
    showX: function() { console.log(x); },
    showX2: showX,
    x: 7
  }
}

test();

obj.showX(); // ??
obj.showX2(); // ??
What will the console output be?
5, 5
5, 6
5, 7
6, 5
6, 6
6, 7
7, 5
7, 6
7, 7
An error will occur.
The function permanently fixes its lexical environment (scope) in the place where the function literal is written.
Rate the difficulty of the question:
easyhard