alert(a || b); // When a is true, there is no reason to evaluate b. alert(a && b); // When a is false, there is no reason to evaluate b. alert(c ? t : f); // When c is true, there is no reason to evaluate f. alert(a || b); // if a is true, return a, otherwise return b alert(a && b); // if a is false, return a, otherwise return b var s = t || "(default)"; // assigns t, or the default value if t is null, empty, etc. str = "ab" + "cd"; // "abcd" str += "e"; // "abcde" str2 = "2"+2 // "22", not "4" or 4. // SWICH: switch (expr) { case SOMEVALUE: //statements; break; case ANOTHERVALUE: //statements; break; default: //statements; break; } var z; var x= z || 1; switch (x) { case 2: alert(""); break; case 1: alert(x); default: //statements; break; } //IN: for (var property_name in some_object) { //statements using some_object[property_name]; } var person={fname:"John",lname:"Doe",age:25}; for (x in person) { alert(person[x] + " "); } //Object literals and array literals allow one to easily create flexible data structures: var myStructure = { name: { first: "Mel", last: "Smith" }, age: 33, hobbies: ["chess", "jogging"] }; -------------------- var myStructure = { name: { first: "Mel", last: "Smith" }, age: 33, hobbies: ["chess", "jogging"] }; for (x in myStructure) { alert(myStructure[x] + " "); } //Object //33 //chess,jogging alert(myStructure.name.first); //Mel alert(myStructure.hobbies[0]); //chess
Sunday, 20 November 2011
JavaScript_syntax
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment