09. session 9 operators and statements

672 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
672
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

09. session 9 operators and statements

  1. 1. Operators and Statements Session 9
  2. 2. Objectives Describe assignment operators Explain bitwise operators Explain switch-case statement Describe regular expression
  3. 3. Types of Operators Operators help in simplifying expressions. JavaScript provides a predefined set of operators that allow you to perform different operations. Arithmetic operators Relational operators Logical operators Assignment operators Bitwise operators Special operators
  4. 4. Arithmetic Operator Arithmetic operators are binary operators, as they perform basic arithmetic operator on two operand.
  5. 5. Increment and decrement operators The increment operator (++) increases the value by 1, while the decrement operator(--) decreases the value by 1.
  6. 6. Relational Operators Relational operators are binary operators that make compare between two operands. They return a boolean value namely, true or false.
  7. 7. Logical Operators Logical operators are binary operators that perform logical operations on two operands.
  8. 8. Assignment Operators Assignmentoperator performs operations between the twooperands and assign the result to its left operand.
  9. 9. Bitwise OperatorsBitwise operators perform operations on the correspondingindividual bits of two operands.
  10. 10. Special Operators•There are some operators in Javascript, which do notbelong to any of the categories of JavaScript operators
  11. 11. String OperatorsCan merge two string values that are assigned totwo different variables. Operator Descriptin Example + Concatenates two or var fullname=‘John’ + ‘ ’ + more strings into a ‘Blake’; single string fullname=‘John Blake’ += Concatenates to or var flower=‘Rose’; (Add-By-Value) more strings and flower +=‘’ + ‘flower’; assign the result to its flower =‘Rose Flower’; left operant
  12. 12. Shift OperatorsShift operators are binary bitwise operators that perform shift operations onbits. The first operand is the decimal number on which the shift operation isperformed. The second operand specifies the number or bit positions bywhich the bits are to be shifted. Operator Description Example << Shift the bit positions 8<<2 yield 32,because 00001000 (Left Shift towards the left by shifting shifted by 2 bits becomes Operator) the number of bits in the 00100000,which is 32. Here, the left at the right two leftmost bits are placed toward the right >> Shift the bit positions 8>>2 yield 32,because 00001000 (Right Shift towards the right by shifting shifted by 2 bits becomes Operator) the number of bits in the 00000010,which is 2. Here, the right at the left two rightmost bits are placed toward the left.
  13. 13. Decision – making StatementDecision-making statement s allow implementing logicaldecision for executing different block to obtain the desiredoutput. They execute a block of statements depending upon aboolean condition.This condition is an expression that returns either true orfalse.Javascript supports four decision-making statements : If If-else If-else if else switch
  14. 14. The “if” StatementThe if statement executes a block ofstatements based on a logical booleancondition.
  15. 15. The “if-else” StatementThe if statement specifies a block ofstatement to be executed when thecondition in the if statement is true, andit’s requires to define a block ofstatements to be executed when aconditions evaluated to false
  16. 16. The “if-else if ” StatementThe if-else if statements allow youto check multiple conditions andspecify a different block to beexecute for each condition.
  17. 17. Nested “if” StatementThe nested if statements comprises ofmultiple if statements within an ifstatement.
  18. 18. “Switch-case” StatementTo simplify the coding and avoid using multiple ifstatement, switch-case statement can be used as adifferent approach to code the same logic
  19. 19. Regular Expressions A regular expression is a pattern, whose purpose is to help invalidating the text format Example:
  20. 20. TypesCharacter or symbols allow matching a substring that exists ata specific position within a string.
  21. 21. TypesCharacters or symbols are combined to form character classes forspecifying patterns.
  22. 22. SummaryThe & operator perform bitwise AND operation andreturns the result to the operand on the left hand sideThe | operator performs bitwise OR operation andreturns the result to the operand on the left hand sideThe ^ operator performs bitwise XOR operation andreturns the result to the operand on the left hand sideThe string concatenation operator combine differentstrings into single string.
  23. 23. Summary… The left shift operator shifts the bits on the leftmost side toward the right. The right shift operator shifts the bits on the rightmost side toward the left. Nested switch-case construct refers to including a switch-case construct within a case block. Building Dynamic Websites/Session 1/ 23 of 16

×