首页 > 编程语言 > [JavaScript-03]IF 三元表达式 逻辑运算 == ===

[JavaScript-03]IF 三元表达式 逻辑运算 == ===

时间:2022-11-09 23:34:29浏览次数:40  
标签:03 逻辑运算 console log 10 color JavaScript else const

1. 语句

// if 语句
let x = 10;
if (x == 10) 
{
    console.log('x is 10')
};

// if else if  else
x = 20;
if (x === 10) 
{
    console.log('x is 10');
} else if (x > 10) 
{
    console.log('x is greater than 10');
} else
{
    console.log('x is less than 10');
}

// 三元表达式
const xxx = 9;
// ?后面为真 :为else
const color = xxx > 10 ? 'red' : 'blue'
console.log('xxx color:',color);

2. 其他应用

// == 不管类型只管值 === 类型和值必须一致
if (x === '10') {
    console.log('x is 10');
};

// 逻辑运算
// false:undefined,0,"",null,false
// || 或
const xx = 11;
if ( xx <6 || xx >10)
{
    console.log('逻辑(或):成立');
}else
{
    console.log('逻辑(或):不成立');
}

// && 与
const yy = 9;
if (yy >1 && yy < 10)
{
    console.log('逻辑(与)成立');
}else
{
    console.log('逻辑(与)不成立');
}

END

标签:03,逻辑运算,console,log,10,color,JavaScript,else,const
From: https://www.cnblogs.com/leoshi/p/16875577.html

相关文章

  • [JavaScript-04]Switch
    1.Switch//Switch语句constcolor='green';switch(color){case'red':console.log('colorisred');break;case'blue':......
  • [JavaScript-02]FOR WHILE循环
    1.语句//For语句for(letindex=0;index<=6;index++){console.log(`ForLoopNumber:${index}`);}//While语句leti=0;while(i<=6){c......
  • 题解 AGC033D【Complexity】
    problem定义一个0/1矩阵\(B\)的复杂度为:若\(B\)只由一种数字组成,其复杂度为\(0\)。否则,用一条平行于矩阵\(B\)任意一边的直线将\(B\)划分为两部分,则复杂度......
  • Datagrip2019.1.4导出导入数据,mysqldump: Couldn’t execute 'SELECT COLUMN_NAME
    1, 2,需要mysqldump.exe  安装mysql就有 3,安装Mysql8 需要添加禁用参数:--column-statistics=0 否则报错mysqldump:Couldn’texecute'SELECTCOLUMN_NAME......
  • POJ 1035 Spell checker
    DescriptionYou,asamemberofadevelopmentteamforanewspellcheckingprogram,aretowriteamodulethatwillcheckthecorrectnessofgivenword......
  • JavaScript
    1、什么是JavaScript?JavaScript是一门世界上最流行的脚本语言严格检查:'usestrict'<script>'usestrict'//必须放在第一方行leti=1;</script>2、数据......
  • JavaScript函数
     JavaScript函数JavaScript函数概念    可以储存一段代码的数据类型- 分为两个阶段:函数定义阶段和函数调用阶段- 1.函数定义阶段:把代码放进“盒子”,函数里面代......
  • UESTC 1272 Final Pan's prime numbers
    DescriptionFinalPanlikesprimenumbersverymuch.Oneday,hewanttofindthesuperprimenumbers.Aprimenumbers n(n>4)isasuperprimenumberonlyif ......
  • UESTC 1273 God Qing's circuital law
    DescriptionAsweallknow,GodQingisaverypowerfulACMer.Sheverylikejuniorsisterapprentice,butinUESTC-ACMteam,thereisnojuniorsisterapprentic......
  • PAT (Advanced Level) Practise 1116 Come on! Let's C (20)
    1116.Comeon!Let'sC(20)时间限制200ms内存限制65536kB代码长度限制16000B判题程序S......