Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples.

Similar presentations


Presentation on theme: "Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples."— Presentation transcript:

1 Module 5 JavaScript Operators

2 CS346 Javascript-52 Examples  JS-5 Examples

3 CS346 Javascript-53 Expressions  Expression — combination of literal values, variables, and operators that can be evaluated by JavaScript to produce a result  Operands — variables and literals contained in an expression  Operators — symbols used in expressions to manipulate operands Performs some sort of calculation, comparison, or assignment on one or more values

4 CS346 Javascript-54 Operators  Arithmetic: + - * / % (int remainder)  Increment:++ ++var — Value Incremented Immediately var count = 1; var newCount = ++count; // newCount = 2 var++ — Value Incremented After Line var count = 1; var newCount = count ++; // newCount = 1  Decrement: - - Similar to increment

5 CS346 Javascript-55 Operators  Assignment: = += -= *= /= %= var x=1, y=2; x += y; // x = 3  Comparison: == != > = <= Results in True or False var x=1, y=2; x == y; // returns False  Logical: && || ! Results in True or False var x=1, y=2; var returnVal = x==1 || y==5; // returns True

6 CS346 Javascript-56 Operators  Negation: -  Bitwise: logical operators that work at the bit level (ones and zeros) AND & XOR ^ OR | NOT - Left Shift << Right Shift >> Right Shift (Zero Fill) >>>

7 CS346 Javascript-57 Operators  String + Concatenate var x=“You age is”, y=18; var newStr = x + y; document.write(newStr); // returns Your age is18 document.write(x + “ ” + y + “.”); // returns Your age is 18.  Conditional: boolean? exprT:exprF document.write(“The fee is ”+ (isMem ? “$5” : “$10”));

8 Beware  Variable type is dynamic  Examples 5-1AssignmentExamples.htm  Combination of CSS and Javascript  Generation of well-formed html document 5-2ComparisonExamples.htm 5-3LogicalExamples.htm


Download ppt "Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples."

Similar presentations


Ads by Google