简体   繁体   English

为什么 jsFiddle 不喜欢这个循环?

[英]why does jsFiddle not like this loop?

There seems to be some serious problems with the difference between the fiddles and the kind of javascript statements that actually work when ran on servers.小提琴和在服务器上运行时实际工作的 javascript 语句之间的差异似乎存在一些严重的问题。 Can you guys help me solve this?你们能帮我解决这个问题吗? I've run into this countless times in last few months.在过去的几个月里,我无数次遇到这种情况。 Here's what I have:这是我所拥有的:

<script>
int counter;
int retainer = 0;

for (counter = 1; counter < 10; counter++) {
    retainer = retainer + counter;
}
document.write(retainer);
</script>

can someone tell me why this gives me a blank page when run in a browser?有人能告诉我为什么在浏览器中运行时这会给我一个空白页面吗? does the WRITE() method not working in this way? WRITE()方法不以这种方式工作吗?

There is no int in javascript. javascript中没有int。 All variables are declared using "var"(till ES5) instead irrespective of datatype.无论数据类型如何,所有变量都使用“var”(直到 ES5)声明。 Javascript is dynamically typed language. Javascript 是动态类型语言。 "let" and "const" have been introduced from ES6 onwards从 ES6 开始引入了“let”和“const”

<script>
var counter;
var retainer = 0;

for (counter = 1; counter < 10; counter++) {
    retainer = retainer + counter;
}
document.write(retainer);
</script>

你确定这是一个js代码吗,我记得javascript中没有int

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM