Your code should be giving the below output in console –
2
undefined
Browser console also prints return value of the last statement method or function call. Return value of console.log() is undefined so it prints undefined also.
Try these cases –
Case 1:
function log(y){
console.log(y);
return y + 1;
};
var x = 2;
log(2);
Output –
2 - console.log(y)
3 - return value of log(x)
Case 2:
function log(y){
console.log(y);
return y + 1;
};
var x = 2;
log(x);
console.log(x);
Output –
2 - console.log(y)
2 - console.log(x)
undefined - return value of console.log(x)
Case 3:
function log(y){
console.log(y);
return y + 1;
};
var x = 2;
console.log(x);
log(x);
Output –
2 - console.log(x)
2 - console.log(y)
3 - return value of log(x)
2
Answers
I reset the chrome inspector using the suggested method below and it works fine now.
How to reset chrome inspector?
Your code should be giving the below output in console –
Browser console also prints return value of the last statement method or function call. Return value of console.log() is undefined so it prints undefined also.
Try these cases –
Case 1:
Output –
Case 2:
Output –
Case 3:
Output –