if函数是一种条件语句,用于根据条件执行代码块。 其语法如下:
if (condition) {
// code to be executed if condition is true
}
如果条件为true,则执行在大括号中的代码块。 如果条件为false,则跳过代码块并继续执行后续语句。
例如,以下代码将检查变量x是否等于10,如果是,则打印一条消息:
var x = 10;
if (x == 10) {
console.log("x is equal to 10");
}
输出结果为:x is equal to 10。
Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号