这里是做个测试
hexo搭建教程请移步这里
else if 和可选代码块
发表于
|
分类于
前端笔记
很多人误以为Javascript中有else if,因为我们可以这样来写代码:
1 | if(a) { |
事实上,JavaScript没有else if,但if 和 else只包含单条语句的时候可以省略代码块的{}。下面的代码你一定不会陌生:
1 | if(a) doSomething(a); |
很多JavaScript代码检查工具建议对单条语句也加上{},如:
1 | if(a) { doSomething(a) }; |
else也是如此,所以我们经常用到的else if实际上是这样的:
1 | if(a) { |
if(b) {…} else {…} 实际上是跟在else后面的一个单独的语句,所以带不带{}都可以。换句话说,else if不符合前面介绍的编码规范,else中是一个单独的if语句。
else if极为常见,能省掉一层代码缩进,所以很受青睐。但这只是我们自己发明的方法,切勿想当然地认为这些都属于JavaScript语法的范畴。
Hello World
发表于
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick Start
Create a new post
1 | $ hexo new "My New Post" |
More info: Writing
Run server
1 | $ hexo server |
More info: Server
Generate static files
1 | $ hexo generate |
More info: Generating
Deploy to remote sites
1 | $ hexo deploy |
More info: Deployment