What value does prompt() return if the user clicked the Cancel button?

Submitted by: Administrator
Return value of prompt() function depends on browsers. Most of the browsers return the value as null and some return as empty string (" "). IE is one of the browser which gives the error of empty string when clicked the cancel button by the user, otherwise all the recent browser return the value as null. The code to check this is as follows:
userInput = prompt('Prompt text','Suggested input');
if (userInput) {
// do something with the input
}
Submitted by:

Read Online Expert Developer JavaScript Job Interview Questions And Answers