JavaScript:跳过const的最佳方法是什么

时间:2019-06-13 16:23:37

标签: javascript skip

如果满足条件,我想跳过块语句。

version: "3"
services:
  web:
    image: conatinera:latest
    networks:
      mynetwork: {}
    deploy:
      replicas: 1
      resources:
        limits:
          cpus: "0.5"
          memory: 4G 
      restart_policy:
        condition: on-failure
    ports:
      - "18080:8080"
networks:
  mynetwork:
    external: true
    name: host

//如果要检查以下条件,我想跳过isJQuery。

const isJQuery = apps[key].technology === "jQuery";

任何帮助都会有所帮助。 我尝试过

      if (!apps[key].aemSchema ) {
        additionalErrors.push(
          `There is no schema defined for ${key} (aka ${apps[key]})!`
        );
      } else if (!schemas[apps[key].aemSchema] ) {
        additionalErrors.push(
          `No schema ${key} (aka ${
            apps[key]
          })! Double check that it exists in  name ${
            apps[key].aemSchema
          }, and that the version included here is right.
          `found apps was `,
          apps
        );
      }

但这将始终检查第一个条件。

1 个答案:

答案 0 :(得分:1)

正如我在上面的评论中所述,if语句中的表达式是按照列出的顺序进行检查的。如果您使用&&,则第一个false条件将退出if。如果您使用||,则第一个true条件将退出if。在您的情况下,我可能只将if放在条件检查的第一级:

if (!isJquery) {
    // Other if/else statements inside
}