当前位置:网站首页>Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
2022-07-02 12:45:00 【By the Difeng River】
List of articles
again i++ and ++i
let i = 1;
alert(i++ + ++i + i) //7

Comparison operator
Use of comparison operators 
alert(5 == "5") //true
alert(5 === "5") //false
alert(5 !== "5") //true
- String comparison , Is the character corresponding to the comparison ASCII code
Compare from left to right
If the first is the same, compare the second , And so on
Relatively few , Understanding can - NaN Not equal to any value , Include It itself
- As far as possible Don't compare decimals , Because there is a precision problem with decimals
- Implicit conversion occurs when comparing different types
Finally, the data is implicitly transformed intonumberCompare the types again
So in development , If we make an accurate comparison, we prefer === perhaps !==
if sentence
Pay attention to the use of parentheses .
Ternary operator
Judge the maximum value of two numbers
let first = +prompt(" First number :")
let second = +prompt(" The second number :")
alert(first > second ? first : second)
Be careful : there prompt Ahead + No. is very necessary , Implicitly convert to Number type .( Otherwise, enter 5,10 The maximum output result is 5, the reason being that String comparison )
switch sentence
Be careful :switch The data in should be consistent with case The value in is Congruent 
while sentence
//while Simple circulation ATM machine
let total = 0; // It's defined in script Global variables in the block level
let money = 0; // It's defined in script Global variables in the block level
while (true) {
let i = +prompt(` Please select your operation : 1. deposit 2. Withdraw money 3. Check the balance 4. sign out `)
if (i === 4) {
break // Jump out of while loop
}
switch (i) {
case 1:
money = +prompt(" Please enter your deposit amount :")
total += money
break // Jump out of switch loop
case 2:
money = +prompt(" Please enter your withdrawal amount :")
total -= money
break // Jump out of switch loop
case 3:
alert(total)
}
}

for Loop statement multiplication table
<style>
div {
display: inline-block;
height: 25px;
line-height: 25px;
margin: 5px;
background-color: pink;
padding: 0 10px;
border: 1px solid hotpink;
color: deeppink;
border-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, .2);
text-align: center;
}
</style>
</head>
<body>
<script>
// Print a few lines on the outer layer
for (let i = 1; i <= 9; i++) {
// Print a few stars on the inner layer
for (let j = 1; j <= i; j++) {
// Just need it * Switch to 1 x 1 = 1
document.write(`<div> ${
j} x ${
i} = ${
j * i} </div>`)
}
document.write('<br>')
}
</script>
</body>

边栏推荐
- 防抖 节流
- The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
- Fluent fluent library encapsulation
- About asp Net MVC project in local vs running response time is too long to access, the solution!
- Linear DP acwing 896 Longest ascending subsequence II
- AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning
- JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
- Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
- [ybtoj advanced training guidance] judgment overflow [error]
- js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
猜你喜欢

BOM DOM

通过反射执行任意类的任意方法

js2day(又是i++和++i,if语句,三元运算符,switch、while语句,for循环语句)

There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes

Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)

Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold

8 examples of using date commands

Heap acwing 838 Heap sort

线性DP AcWing 902. 最短编辑距离
![JDBC prevent SQL injection problems and solutions [preparedstatement]](/img/32/f71f5a31cdf710704267ff100b85d7.png)
JDBC prevent SQL injection problems and solutions [preparedstatement]
随机推荐
Sweetheart leader: Wang Xinling
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
Deep copy event bus
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
spfa AcWing 851. spfa求最短路
Interview questions for software testing - a collection of interview questions for large factories in 2022
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
浏览器存储方案
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
8A 同步降压稳压器 TPS568230RJER_规格信息
线性DP AcWing 902. 最短编辑距离
Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
"As a junior college student, I found out how difficult it is to counter attack after graduation."
深拷贝 事件总线
Hash table acwing 840 Simulated hash table
spfa AcWing 852. spfa判断负环
Do you know all the interface test interview questions?