JavaScript judgment and looping

Source: Internet
Author: User
Tags switch case

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.