Skip to content
Advertisement

Variable not displayed in console.log

here is my code.

JavaScript

expected output

JavaScript

actual output

JavaScript

Why is it showing ‘undefined` ?

Advertisement

Answer

you are trying to assign the console.log to userName and using it. change the code to

JavaScript

or you can use the line as follows.

JavaScript

JavaScript
Advertisement