Javascript Learning (2) -- [basic review] operators, expressions, and flow control statements

Source: Internet
Author: User
Well, let's simply put the following OPERATOR: operator Description Example result + + Add xy + 2x7-minus xy-2x3 * multiply xy * 2x10 except xy2x25 % evaluate the remainder (keep the integer) xy % 2x1 ++ well, let's simply say the operator, paste a table: operator Description Example result + Add x = y + 2 x = 7-minus x = y-2 x = 3 * multiply x = y * 2 x = 10/divide x = y/2 x = 2.5% evaluate the remainder (Reserved integer) x = y % 2 x = 1 + + accumulate x = + y x = 6 -- decrease x = -- y x = 4 = x = y x = 5 + = x + = y x = x + y x = 15-= x-= y x = x-y x = 5 * = x * = y x = x * y x = 50/= x /= y x = x/y x = 2% = x % = y x = x % y x = 0 OK, I guess everyone would dislike me ?? Aluminum player? Can you tell me how to cut the stool? /Div> post code description-branch: [javascript]/*** Branch */(function () {/** if (condition ){//...} if (condition ){//..} else if (condition ){//..} else {} * // experiment var d = new Date (); var time = d. getHours (); if (time> = 18) {document. write (" Good evening")} Else {document. write (time)} // Experiment 2 if (time <10) {document. write (" Good, morning")} Else if (time >=10 & time <16) {document. write (" Good, day")} Else {document. write (" Good evening");} // Experiment 3 // operator (condition )? "True": "failed" var str = ""; str = (time> 10 )? "Good, day": "good evening"; // alert (str);/*** the (n) after the switch can be an expression or a variable switch (n) {case 1: // code break; case 2: // code break; default: // code break;} */document. write ("
") TheDay = d. getDay (); switch (theDay) {case 5: document. write ("finally Friday"); break; case 6: document. write ("super zhouliu"); break; case 0: document. write ("sleepy Sunday"); break; default: document. write ("xiwang A zhoum") ;}}) () Post code to talk about "loop" [javascript]/*** loop */(function () {/** for (variable = start value; variable <= end value; variable = variable + step) {} */var arr = [,]; for (var I = 0; I <arr. length; I ++) {document. write (arr [I] +"
")}/** While (variable <= end value) {} */var I = arr. length-1; while (I> = 0) {document. write (I + "-->" + arr [I] +"
"); I --;}/*** for (variable in object) {*} */var o = {name:" USPCAT ", age: 1 }; for (k in o) {document. write (k + "-->" + o [k] +"
") ;}}) () Post code to talk about other scattered knowledge: [javascript]/*** other scattered knowledge of js */(function () {// 1 exception capture // try {//} catch (e) {//} try {// alert (2/0)} catch (e) {// throw new Error (e)}) ()/*** timer * setTimeout * execute a code segment in a future */function timedMsg () {// function var t = setTimeout ("alert ('1 miao zhong ')", 1000);} var c = 0; var t; function timedCount () {document. getElementById ("txt "). value = c; c = c + 1; t = setTimeout ("timedCount ()", 1000)} function stop () {clearTimeout (t );}

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.