How do I use the second parameter in the JavaScrip

2019-09-21 15:45发布

What is the second parameter used for in the prompt() function?

prompt('blahblahblah', 'WHY ARE THESE HERE? '){}

标签: javascript
3条回答
淡お忘
2楼-- · 2019-09-21 16:22

The second param is for a value argument:

value is a string containing the default value displayed in the text input field. It is an optional parameter. Note that in Internet Explorer 7 and 8, if you do not provide this parameter, the string "undefined" is the default value.

https://developer.mozilla.org/en-US/docs/DOM/window.prompt

查看更多
欢心
3楼-- · 2019-09-21 16:29

I'm going to assume that you wrote parenthesis parentheses but meant parameter. I'm assuming this because you also mentioned the comma character and that only appears within the argument list of the command...

The second parameter in the prompt command is the default value that is inserted into the text field.

Here is a simple example -

var milliseconds = (new Date).getTime();
var currentEpoch = Math.floor(milliseconds / 1000);
prompt("What is the current epoch?",currentEpoch);
查看更多
男人必须洒脱
4楼-- · 2019-09-21 16:39

{} defines an empty code block. It does exactly nothing.

It makes more sense to have a code block after control structures such as if and for.

查看更多
登录 后发表回答