javascript - If, else if, statements : Uncaught ReferenceError: Invalid left-hand side in assignment
问题描述
我刚开始做 Javascript,我不断收到语法错误,但没有设法找出它的来源。这是我写的一个片段:
let num1 = 5;
let num2 = 8;
let num3 = 10;
if (num1 === num2) {
console.log("the comparison shows");
} else if (num1 > num2 = true); {
console.log("Number 1 is greater than number 2. The value for num 1 is " + num1);
} else(num2 > num1 = true); {
console.log("Number 2 is greater and the value is " + num2);
解决方案
在 else if 和 else 块之后删除;
,不需要在 else-if/else 语句中将表达式等同于 true。不需要 else 语句中的条件。如果以上都没有通过,则控制将只转到 else
let num1 = 5;
let num2 = 8;
let num3 = 10;
if (num1 === num2) {
console.log("the comparison shows");
}
else if (num1 > num2) {
console.log("Number 1 is greater than number 2. The value for num 1 is " + num1);
}
else
console.log("Number 2 is greater and the value is " + num2);
推荐阅读
- sql - 在 Node.JS 中使用 SQL 在概念上是错误的吗?
- sql - 数据集转置
- python - 如何在 Tensorflow 中对 RaggedTensor 进行切片
- ruby-on-rails - 如何在 Rails 中根据连接表范围检索关联
- reactjs - 从表中删除值
- pdf - 可以在 jupyter notebook markdown 中指定作者,以便 nbconvert 将其用于 PDF 文章作者吗?
- inno-setup - InnoSetup:文件检查功能有问题
- opengl - 如何将 OpenGL 渲染场景从云端传输到远程客户端
- python - VSCode Python 调试器在未执行的行上执行 - 并在正在执行的行上执行
- ios - SwiftUI - 限制视图内矩形的拖动