Tag: greater than operation break nbsp ternary operator Switch script case BSP
Three judgments: if else, ternary operator, can solve all the problems in JS
Switch case Example: var a = 10; if (a<0) {console.log ("negative")}else if (a>=0&& a<=10) {console.log ("0-10")}else (a>10) {Console.log ("Greater than 10")} Ternary operator Condition: condition is set up to execute: condition does not set up execution; var a = 10; if (a>=0) {Console.log ("positive number or 0")}else{console.log ("negative number")}num>=?console.log ("positive number or 0"): Console.log ("negative number"); Switch case//each case with a break, and if no break equals the subsequent default, the var a = 10;switch (a) {case 0:console.log ("0") and Break;case 5: Console.log ("5"); Break;case 10:console.log ("ten"); Break;default:console.log ("NaN");} For In loop: var obj = {name: "Zhang San", Age:18,height: "170cm", Hobby: "Basketball"} used to loop properties and property values in an object; for (var key in obj) {console.log (key);//Property name: Name Age height Hobby console.log (Obj[key])//property value: 318 170cm Basketball}
JavaScript judgment and looping