Essentials of Javascript - Cultural View
Essentials of Javascript - Cultural View Essentials of Javascript - Cultural View
JavaScript syntax 31 Assignment = Assign += Add and assign -= Subtract and assign *= Multiply and assign /= Divide and assign %= Modulus and assign var x = 1; x *= 3; alert( x ); // displays: 3 x /= 3; alert( x ); // displays: 1 x -= 1; alert( x ); // displays: 0 Comparison == Equal != Not equal > Greater than >= Greater than or equal to < Less than
JavaScript syntax 32 alert( Boolean( -2 ) === true ); // All objects return true alert( Boolean( this ) === true ); alert( Boolean( {} ) === true ); alert( Boolean( [] ) === true ); // These types return false alert( Boolean( null ) === false ); alert( Boolean( undefined ) === false ); // equivalent to Boolean() The NOT operator evaluates its operand in as a Boolean, and returns the negation. Using the operator twice in a row, as a double negative, explicitly converts an expression to a primitive of type Boolean: alert( !0 === Boolean( !0 ) === !!1 === Boolean( 1 ) === true ); alert( !!0 === Boolean( 0 ) === !1 === Boolean( !1 ) === false ); alert( !"" === Boolean( !"" ) === !!"s" === Boolean( "s" ) === true ); alert( !!"" === Boolean( "" ) === !"s" === Boolean( !"s" ) === false ); Expressions that use features such as post–incrementation, (i++), have an anticipated side effect. JavaScript provides short-circuit evaluation of expressions; the right operand is only executed if the left operand does not suffice to determine the value of the expression. 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. In early versions of JavaScript and JScript, the binary logical operators returned a Boolean value (like most C–derived programming languages). However, all contemporary implementations return one of their operands instead: alert( a || b ); // if a is true, return a, otherwise return b alert( a && b ); // if a is false, return a, otherwise return b Programmers who are more familiar with the behavior in C might find this feature surprising but it allows for a more concise expression of patterns like null coalescing: var s = t || "(default)"; // assigns t, or the default value if t is null, empty, etc.
- Page 1 and 2: Essentials of Javascript Visit the
- Page 3 and 4: John Resig 122 Reverse Ajax 123 Ric
- Page 5 and 6: JavaScript 2 History Anyway I know
- Page 7 and 8: JavaScript 4 Prototype-based protot
- Page 9 and 10: JavaScript 6 LCMCalculator.prototyp
- Page 11 and 12: JavaScript 8 Example - use in web p
- Page 13 and 14: JavaScript 10 request that might ha
- Page 15 and 16: JavaScript 12 Application platform
- Page 17 and 18: JavaScript 14 See also • Client-s
- Page 19 and 20: JavaScript 16 [25] Robert Nyman, Ge
- Page 21 and 22: JavaScript syntax 18 JavaScript syn
- Page 23 and 24: JavaScript syntax 20 Primitive data
- Page 25 and 26: JavaScript syntax 22 String A Strin
- Page 27 and 28: JavaScript syntax 24 Native Objects
- Page 29 and 30: JavaScript syntax 26 } Math The Mat
- Page 31 and 32: JavaScript syntax 28 // ? - 0 or 1
- Page 33: JavaScript syntax 30 Operators The
- Page 37 and 38: JavaScript syntax 34 Conditional op
- Page 39 and 40: JavaScript syntax 36 With The with
- Page 41 and 42: JavaScript syntax 38 Methods A meth
- Page 43 and 44: JavaScript syntax 40 Inheritance Ja
- Page 45 and 46: JavaScript syntax 42 See also • C
- Page 47 and 48: JavaScript Style Sheets 44 } fontSi
- Page 49 and 50: JavaScript engine 46 JavaScript eng
- Page 51 and 52: Ajax (programming) 48 Ajax (program
- Page 53 and 54: Ajax (programming) 50 • Ajax-powe
- Page 55 and 56: ?: 52 ?: In computer programming, ?
- Page 57 and 58: ?: 54 Furthermore, the ternary oper
- Page 59 and 60: ?: 56 ?: in style guidelines Some c
- Page 61 and 62: Appcelerator Titanium 58 See also
- Page 63 and 64: Bookmarklet 60 Bookmarklet A bookma
- Page 65 and 66: Bookmarklet 62 References [1] Domai
- Page 67 and 68: Client-side JavaScript 64 implement
- Page 69 and 70: Client-side JavaScript 66 Reference
- Page 71 and 72: dhtmlx [1] Comparison of JavaScript
- Page 73 and 74: ility / ion Comparison of JavaScrip
- Page 75 and 76: Comparison of JavaScript frameworks
- Page 77 and 78: Comparison of JavaScript frameworks
- Page 79 and 80: Comparison of JavaScript-based sour
- Page 81 and 82: Comparison of JavaScript-based sour
- Page 83 and 84: Douglas Crockford 80 Douglas Crockf
JavaScript syntax 31<br />
Assignment<br />
= Assign<br />
+= Add and assign<br />
-= Subtract and assign<br />
*= Multiply and assign<br />
/= Divide and assign<br />
%= Modulus and assign<br />
var x = 1;<br />
x *= 3;<br />
alert( x ); // displays: 3<br />
x /= 3;<br />
alert( x ); // displays: 1<br />
x -= 1;<br />
alert( x ); // displays: 0<br />
Comparison<br />
== Equal<br />
!= Not equal<br />
> Greater than<br />
>= Greater than or equal to<br />
< Less than<br />