语法:条件?表达式1:表达式2 。  条件的括号可要可不要的

                    let istrue = true;

                    let a = (istrue === true) ? '我是true啊' : "我是false啊";
console.log(a) //我是true啊 let b = '';
(istrue === false) ? b = '我是true啊': b = '我是false啊';
console.log(b)//我是false啊

经常使用的js三元表达式的更多相关文章

  1. JS——三元表达式

    三元表达式: var n1 = 2 > 3 ? true : false; alert(n1);//返回false

  2. js 三元表达式

    JavaScript三元运算符的多种使用技巧 发现代码慢慢写多了的时候会不自觉的将if else 用 三元来替代,仅仅是未了让代码更简洁精辟,当然也有人说用三元可以让你有高潮的感觉.最近在写js 的时 ...

  3. js三元表达式

    条件 ? true的时候执行 : false时候执行 const x = 20; let answer; if (x > 10) { answer = 'greater than 10'; } ...

  4. js 三元表达式的写法

    句式一. if(a) do_a elseif(b) do_b else do_c 转化为: =>a ? do_a : b ?do_b : do_c 句式二. if(a) do_a 转化为: =& ...

  5. js 三元表达式 复杂写法

    a = 0 b = 0 a === 0 && (a = 1,b = 2) a === 1 ? (a = 3,alert(b)) : (b = 4) a === 1 || alert(a ...

  6. JS学习笔记 - fgm练习 - 输入法下拉框 三元表达式

    <script> window.onload = function() { var oBtn = document.getElementsByTagName('input')[0]; va ...

  7. JS基础语法---分支语句之:三元表达式

    获取两个数字中的最大值 用if-else语句        var num1 = 10;        var num2 = 100;        if (num1 > num2) {     ...

  8. thinkphp3.2.3模板渲染支持三元表达式

    thinkphp3.2.3模板渲染支持三元表达式 {$status?'正常':'错误'} {$info['status']?$info['msg']:$info['error']} 注意:三元运算符中 ...

  9. [LeetCode] Ternary Expression Parser 三元表达式解析器

    Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...

随机推荐

  1. 第一章 impala的安装

    目录 第一章 impala的安装 1.impala的介绍 imala基本介绍 impala与hive的关系 impala的优点 impala的缺点: impala的架构以及查询计划 2.impala的 ...

  2. spring boot 项目开发常用目录结构

    在spring boot开发中一些常用的目录划分 转载自https://blog.csdn.net/Auntvt/article/details/80381756: 一.代码层结构 根目录:net.c ...

  3. 解决MFC实际运行对话框与测试对话框显示效果不一致问题

    1.打开#include  "stdafx.h"头文件文档 2.在末尾加上#define  _UNICODE即可

  4. c++ erase 中的坑

    先看一段正常的代码 #include <iostream> #include <string> using namespace std; int main() { " ...

  5. k8s遇坑:The connection to the server k8s-api.virtual.local:6443 was refused - did you specify the right host or port?

    k8s坑The connection to the server localhost:8080 was refused - did you specify the right host or port ...

  6. Spring 容器中 Bean 的生命周期

    Spring 容器中 Bean 的生命周期 1. init-method 和 destory-method 方法 Spring 初始化 bean 或销毁 bean 时,有时需要作一些处理工作,因此 s ...

  7. java——ArrayList中remove()方法疑问总结

    其实remove方法和contains方法大同小异,它的原理和contains方法相同https://www.cnblogs.com/lyxcode/p/9453213.html在这篇博客里面有详细说 ...

  8. squoosh

    谷歌在线压缩图片

  9. SQL的GROUP BY 与 Order By

    1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简 ...

  10. vue transtion 实现分析

    这是我用js和css3,实现的vue transition组件相同的效果核心js var btn = document.getElementById('btn'); var box = null bt ...