I was solving one of the problem on the site and came across a very bizarre incident.
Here, is the IDE already written function is as
// The global variable
var fixedValue = 4;
function incrementer () {
// Only change code below this line
// Only change code above this line
}
Problem Statement : Fill in the code for the function incrementer
so it returns the value of the global variable fixedValue
increased by one.
I wrote a solution which is wrong and compiled correctly which it should not
My answer :
var fixedValue = 4;
function incrementer () {
return ++fixedValue
}
Now if i do console.log(fixedValue) outside the function scope it will output 5 and this answer is accepted by the system. Why?