# 章序号/节序号/节/笔记序号 codecademy, Condition # 概念阐释 - 当判断结果为`false`时,我们不想没有内容,可以让计算机执行false情况下可执行的代码 - `else`语句必须和`if`语句同时使用。 - `else`后面直接跟花括号`{}`,里面是要执行的代码 ## 语法 ![](http://image.harryrou.wiki/2023-01-09-%E6%88%AA%E5%B1%8F2023-01-10%2006.10.34.png) # 举例子 ```js if (false) {   console.log('The code in this block will not run.'); } else {   console.log('But the code in this block will!'); } // Prints: But the code in this block will! ``` # 类比、比较与对比 # 问题 - 设定一个变量名称为sale - 当sale为true时,print 'Time to buy!'' - 当sale为false时,print 'Time to wait for a sale.' # 问题答案 ```js let sale=false; if(sale){ console.log('time to buy.'); }else { console.log('time to wait for a sale.'); } ``` # 备注(经验集/错误集)