小编gui*_*mus的帖子

在循环javascript中声明变量

我不明白这段代码.

var timesTable;
while ((timesTable = prompt("Enter the times table", -1)) != -1) {.....}
Run Code Online (Sandbox Code Playgroud)

为什么有必要在之前声明变量?我试着这样做:

while ((var timesTable = prompt("Enter the times table", -1)) != -1) {.....}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.有什么问题?是关于范围的吗?

完整的计划是:

function writeTimesTable(timesTable, timesByStart, timesByEnd) {
        for (; timesByStart <= timesByEnd; timesByStart++) {
            document.write(timesTable + " * " + timesByStart + " = " + timesByStart * timesTable + "<br />");
            }
        }
    var timesTable;
    while ((timesTable = prompt("Enter the times table", -1)) != -1) {
        while (isNaN(timesTable) == true) {
            timesTable …
Run Code Online (Sandbox Code Playgroud)

javascript scope function while-loop

0
推荐指数
1
解决办法
1760
查看次数

标签 统计

function ×1

javascript ×1

scope ×1

while-loop ×1