Is it okay to call prompt this way:
prompt('Enter your text here');
instead of:
prompt('Enter your text here', '');
I.e. without passing a suggested input to it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it is OK.
The second parameter to
promptmethod is optional (see “window.prompt on MDN”).As according to ECMAScript specification (ECMA-262, section 4.3.9), a value of
undefinedis given to a variable which has no assigned value. In thepromptmethod, it doesn’t matter whether you leave the second parameter asundefinedor pass an empty string to it: both result in empty string as default value in the prompt.In case you are wondering why this information is not available on DOM standards such as W3C DOM the answer is that it is a non-standard method that is “just” commonly supported by browsers (part of so called “DOM Level 0” spec). However, the upcoming HTML 5 is likely to define prompt (
window.prompt) as a standard method (see “6.4 User prompts”).