


JS uses switch to determine the code sharing of ternary operation while and attribute operation
This article mainly introduces JS switch to judge the ternary operation while and attribute operation code. Friends who need it can refer to
Ternary operation: such as var a = 10;
var b= 12; c = a>b ?a:b;
If true, execute a, otherwise execute b
var isHide = true;
If you use if to judge the statement as follows
if(isHide) { box.style.display = "block"; } else { box.style.display = "none"; }
Ternary operation replaces if
box.style.display = isHide?"block":"none";
Judgment condition? The execution statement is established: the execution statement is not established.
If the condition is true, return: the result of the execution is true
The condition is not true: the result of the execution
Simplified version of if judgment
continue Skip this loop: cannot write ternary operation
column:
for(var i=0;i<5;i++){ if(i==3) continue;跳过i=3这个循环不执行;其他依然执行。 }
break: terminate the entire loop; by default, only the immediately adjacent loop will be terminated If you want to terminate other loops, you need to give the loop a name.
Example:
for(var i=0;i<5;i++){ if(i==3) break;当循环执行到i=3时终止整个循环。 } name:for(var i=0;i<5;i++){ for(var j=0;j<5;j++){ break name //终止两个循环 } }
The object stores data, which is stored in the properties of the object:
The object is a complex type of data , we can store any type of data in the object
The first type: attribute operation 1 The first type of attribute operation is a set of hard-coded values, and variables cannot be used.
Read operation obj.Attribute name
Write operation obj.Attribute name = attribute value;
obj.key = val;Key value pair;
For example,
var obj = {}; obj.name = "Leo"; 这种写法为第一种属性名都被写死若想调用必须要如 obj.age = 40; 下console.log(obj.name);。 obj.gender = "female"; console.log(obj.w);//注意第一种属性操作是写死的一个值,不能使用变量 obj.w 这么写就认为在找 obj的w属性。
The second attribute operation is done. What is received is a string. The string can be stored in a variable. You can directly write obj[variable Call]
Read operation obj["Attribute name]
obj["Attribute name"]=Attribute value;
obj["key"] = val;
Note The second type
such as
var obj = {}; obj['name'] = "Leo"; obj['age'] = 40; obj['gender'] = "female"; obj['width'] = "180px"; obj['height'] = "180px"; obj['children'] = ["大明","小明","三明"]; var w = "width"; console.log(obj[w]);// 第二种属性操作,接受的是一个字符串,字符串就可以存在变量中,可以直接写obj[变量调用]; alert("name" in obj); // obj 有 name属性就返回 true,否则 返回false
determines whether there is this attribute in the object
returns true or false
for (var s in obj) { 找到obj的所有属性 s会依次变成arr的属性名 //同过in方法将循环变量s变成obj对 console.log(s,obj[s]); 应的属性名。若想使用只有用第二中命名。s的类型是字符串。 } s为属性名 obj[S]为对应的属性名的属性值。
for in can be used to loop objects and arrays but cannot be used to loop a group of elements.
for loop can only be used to loop arrays (a group of elements) and cannot be used Loop through a group of objects
##
###while语句### 起始值 while(判断条件){ 执行语句; 自增; } ##switch## switch(要判断的内容){ case:判断内容; //条件成立后执行语句将case下所有代码都执行,只有遇见break才会结束 执行语句; 若没有遇见break就会遇见穿刺现象执行所有代码。 break; default: //以上所有的判断都不成立 }
##
switch(a){ case 10://当a == 10; console.logo(“;;;;”)语句结束之后添加break break;//当a==10 的 case 15://当a==15; console.logo("ppppp") break; default: //以上所有的判断都不成立 }
The above is the detailed content of JS uses switch to determine the code sharing of ternary operation while and attribute operation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Can Elden's Ring be played on the switch? As a very charming action RPG game, many friends may not know whether it can be played smoothly on the switch platform. The answer is that it cannot be played at the moment. accomplish. Can Ring of Elden be played on switch? Answer: It cannot be played on switch. This highly anticipated Souls series role-playing action game has been officially released. Players can purchase it on PC, PS4/5 and Xbox Series eX|S/XboxOne and experience it immediately. Many friends who own a switch may still be eager to enjoy this game on the NS, but unfortunately, there is no switch version of the game. According to the official website configuration requirements, the game configuration is relatively high, and sw

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Switch2 is a new model announced by Nintendo at Gamescom 2023. Some players are worried about whether there will be compatibility issues between the new model and the cartridges of previous versions. Let’s take a look. Is switch2 compatible with switch cassette? Answer: switch2 is not compatible with switch cassette. Introduction of Switch 2 cartridges According to information from Nintendo’s production chain company, Switch 2 may use 64GB cartridges. Because it has better performance and supports more 3A game masterpieces, it requires a larger cartridge capacity. Because many game works need to be castrated and compressed before they can be stuffed into a game cartridge. Moreover, Switch cartridges are prone to copying game content, so replace them with new cartridges.

As a powerful relational database management system, Oracle database provides a wealth of computing operations to meet user needs. In daily database operations, subtraction operation is a common and important operation. It can help us realize the subtraction operation of data to obtain the results we need. This article will discuss in detail the techniques related to subtraction operations in Oracle database, and give specific code examples to help readers better understand and use this function. 1. Basic concepts of subtraction operations in Oracle data

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

PHP is a scripting language widely used in website development. Its powerful functions and flexibility make it the tool of choice for many developers. However, PHP also has some problems when dealing with floating point operations, especially when it comes to precision and accuracy. This article will analyze PHP floating point operation problems and propose some solutions. It will also provide specific code examples to help readers better understand and solve these problems. Problem Analysis In PHP, floating point numbers are a data type used to represent decimals.

Overview of how to use WebSocket and JavaScript to implement an online electronic signature system: With the advent of the digital age, electronic signatures are widely used in various industries to replace traditional paper signatures. As a full-duplex communication protocol, WebSocket can perform real-time two-way data transmission with the server. Combined with JavaScript, an online electronic signature system can be implemented. This article will introduce how to use WebSocket and JavaScript to develop a simple online

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.
