The use of JS variables [pop-up input box, prompt user name to enter name; pop-up a dialog box, output the name just entered by the user]

1. Code

<script>
    //1.输出用户名 并存储到一个变量中
    var myname = prompt('请输入您的名字');
    //2.输出这个用户名
    alert(myname);
</script>

2. Results display

1. Input name
insert image description here
2. Output name
insert image description here

3. Supplementary variables

1. The variable is only declared but not assigned, and the output result is undefined.
2. If a variable is not declared or assigned a value, an error will be reported if a variable is used directly.
3. It can also be used without declaring direct assignment.
4. Try not to use name as a variable name.

Guess you like

Origin blog.csdn.net/m0_46695182/article/details/127147480