|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JS Tutorial
Part I - JS language
Part II- JS objects
Part III - Client-Side JS |
JavaScript Ch3 - Operators
JavaScript supports both binary and unary operators. Binary operators require that there were two operands in the expression, such as 9 + x, whereas unary operators only need one operand, such as ++ x. JavaScript also supports operators that deal with strings and logical values. 3.1 Assignment Operators An assignment operator (=) assigns a value to a variable. When JavaScript encounters an assignment operator, it looks to the right for a value, and then to the left for a place (variable) to store it. If the left is a variable, it assigns the value to it. If the left is not storeable (e.g 20 = x), it throws error.
3.2 Arithmetic Operators Most basic operators include:
3.4 Comparision Operators Here is a list of all the comparison operators:
3.5 String Operators The set of string operators available in JavaScript includes all comparision operators, along with the concatenation operator (+). Using the concatenation operator, you can easily attach strings together to make a longer string. 3.6 Conditional Operators JavaScript uses the set of two operators, ? and :, to form
conditional expressions.
The conditional expression returns <value1> if the
condition is true, otherwise returns <value2>.
Provided that numHits is set equal to 100000 elsewhere in the program, this expression returns the string You have won!; othewise, it returns You lost. Try again. 3.7 Boolean Operators Sytax:
Examples:
|
References(1) Aland Shalloway & James R. Trott, Design Patterns Explained, Second Edition.(2) Allen Holub, Holub on Patterns, Learning Design Patterns by Looking at Code (3) Eric Evans, Domain-Driven Design, Tackling complexity in the heart of software. Advertisement |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||