如果是其他格式 [英] If Else format
问题描述
我O''Reilly的第90页Javascript权威指南第3版
有一个If / Else结构的例子:(删除了一些文字)
If(用户名!= null)
alert(Hello+用户名);
else {
username = prompt("你叫什么名字?);
alert(" Hello" + username);
}
我应该删除第一个" ;;"从第二行开始?
在我的测试中肯定会有更好的效果,但是我不知道这是否是书中的错误
,改变JavaScript的工作方式,或者浏览器中的一个缺陷
。
-
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
On page 90 of my O''Reilly "Javascript The definitive guide" 3rd edition
there is an example of an If/Else construct: (some text removed)
If (username != null)
alert("Hello " + username);
else {
username = prompt("What is your name?");
alert("Hello " + username);
}
Should I erase the first ";" from the second line?
It certainly works better in my tests that way, but I don''t know if this
is an error in the book, a change in the way JavaScript works, or a flaw
in my browser.
--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
推荐答案
Steve Swift schreef:
Steve Swift schreef:
On我的O''Reilly的第90页Javascript权威指南第3版
有一个If / Else结构的例子:(删除了一些文字)
If(用户名!= null)
alert(Hello+用户名);
else {
username = prompt("你叫什么名字?);
alert(" Hello" + username);
}
我应该删除第一个" ;;"从第二行?
On page 90 of my O''Reilly "Javascript The definitive guide" 3rd edition
there is an example of an If/Else construct: (some text removed)
If (username != null)
alert("Hello " + username);
else {
username = prompt("What is your name?");
alert("Hello " + username);
}
Should I erase the first ";" from the second line?
编号为什么要这样?
这是命令的结束,为清楚起见,请使用分号。
No. Why should you?
It is the end of a command, and for clarities sake, use a semicolon.
>
它在我的测试中确实效果更好,但我不知道这是不是这个
本书中的错误,JavaScript工作方式的改变,或浏览器中的缺陷
。
>
It certainly works better in my tests that way, but I don''t know if this
is an error in the book, a change in the way JavaScript works, or a flaw
in my browser.
如果没有分号,它的效果如何?
Erwin Moller
-
============================
欧文Moller
现在放弃googlegroups的所有帖子。
为什么? http://improve-usenet.org/
= ===========================
How does it work better without the semicolon???
Erwin Moller
--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
9月19日,8:17 * am,Steve Swift< Steve.J.Sw ... @ gmail.comwrote:
On Sep 19, 8:17*am, Steve Swift <Steve.J.Sw...@gmail.comwrote:
在我的O''Reilly的第90页上Javascript权威指南 ;第3版
有一个If / Else结构的例子:(删除了一些文字)
If(用户名!= null)
* * alert(" Hello" + username);
else {
* * username = prompt("你叫什么名字?) ;
* * alert(你好+用户名);
}
我应该擦除第一个;从第二行开始?
On page 90 of my O''Reilly "Javascript The definitive guide" 3rd edition
there is an example of an If/Else construct: (some text removed)
If (username != null)
* *alert("Hello " + username);
else {
* *username = prompt("What is your name?");
* *alert("Hello " + username);
}
Should I erase the first ";" from the second line?
我用花括号包裹警告:
If(username!= null ){
alert(Hello+用户名);
} else {
username = prompt("你叫什么名字) ?");
alert(" Hello" + username);
}
-
Jorge。
I''d wrap that alert in curly braces:
If (username != null) {
alert("Hello " + username);
} else {
username = prompt("What is your name?");
alert("Hello " + username);
}
--
Jorge.
Steve Swiftaécrit:
Steve Swift a écrit :
我的O'的第90页'Reilly'Javascript权威指南第3版
有一个If / Else结构的例子:(删除了一些文字)
If(用户名!= null)
On page 90 of my O''Reilly "Javascript The definitive guide" 3rd edition
there is an example of an If/Else construct: (some text removed)
If (username != null)
no ...:if(blah)
(小写)
no ... : if ( blah )
(lowercase)
alert(" ;你好'+用户名};
else {
用户名=提示符("你叫什么名字?);
提醒(你好+用户名);
}
我应该删除第一个;"从第二行?
alert("Hello " + username);
else {
username = prompt("What is your name?");
alert("Hello " + username);
}
Should I erase the first ";" from the second line?
行尾的'';''在JS中是可选的
函数hello(){
if(typeof username ==''undefined''|| username == null)
username = prompt(''你的名字是什么?'')
alert (''你好''+用户名)
}
的工作原理如下:
函数你好( ){
if(typeof username ==''undefined''|| username == null){
username = prompt(''你叫什么名字?'' );
}
alert(''Hello''+用户名);
}
但是......正确编码要好得多。
-
sm
The '';'' in end of line is optional in JS
function hello() {
if(typeof username == ''undefined'' || username == null)
username = prompt(''What is your name?'')
alert(''Hello '' + username)
}
works as well as :
function hello() {
if(typeof username == ''undefined'' || username == null) {
username = prompt(''What is your name?'');
}
alert(''Hello '' + username);
}
But ... it''s much better to code correctly.
--
sm
这篇关于如果是其他格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!