文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
If
最简单的条件判断是 if 语句,语法是 if(condition){ do this … }
。条件判断为真,才执行分支中的代码。举个字符串的例子:
var country = 'France';
var weather;
var food;
var currency;
if(country === 'England') {
weather = 'horrible';
food = 'filling';
currency = 'pound sterling';
}
if(country === 'France') {
weather = 'nice';
food = 'stunning, but hardly ever vegetarian';
currency = 'funny, small and colourful';
}
if(country === 'Germany') {
weather = 'average';
food = 'wurst thing ever';
currency = 'funny, small and colourful';
}
var message = 'this is ' + country + ', the weather is ' +
weather + ', the food is ' + food + ' and the ' +
'currency is ' + currency;
注意: 条件判断可以嵌套。
Exercise 填写 `name` 的值,验证条件判断。
var name =
if (name === "John") {
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论