1 / 19

2440: 211 Interactive Web Programming

2440: 211 Interactive Web Programming. Expressions & Operators. Expressions. Literal value or variable or combination of literal values, variables, operators, and other expressions that can be evaluated to produce a result Literal – value such as literal string or a number

june
Download Presentation

2440: 211 Interactive Web Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2440: 211 Interactive Web Programming Expressions & Operators

  2. Expressions • Literal value or variable or combination of literal values, variables, operators, and other expressions that can be evaluated to produce a result • Literal – value such as literal string or a number • Operands – variables and literals in an expression • Operator – symbols used in expressions to manipulate operands • E.g. addition (+), multiplication (*), etc • Variable – named memory location for storing data Expressions & Operators

  3. Variables • A named memory location for storing data • Identifier – names used for variables, functions, and objects • Rules for naming a variable include the following: • First letter must be a letter or an underscore (_) • The other characters can be letters, numbers, or underscore (_) • Spaces cannot be included • Reserved words (keywords) cannot be used Expressions & Operators

  4. JavaScript Keywords Expressions & Operators

  5. Variable Declaration • Creating a variable for usage • The keyword var is used to declare variables, although not required • E.g. var name; Expressions & Operators

  6. Variable Assignment • Storing data in a variable • Data is stored with the assignment operator (=) • E.g. name = “John Doe”; Expressions & Operators

  7. Variable Initialization • Declaring and assigning data to a variable at the same time • E.g. var name = “John Doe”; Expressions & Operators

  8. Data Types • Category of information stored in a variable • JavaScript supports the following data types: • Numeric – any positive or negative number • Integer numbers – whole numbers • Floating-point numbers – exponents or decimal numbers • Boolean – logical value of true or false • String – text values like “Hello” enclosed in either double (“) or single quotes (‘) • Null – an empty value • Undefined – variables with no assigned value, not declared, or does not exist • Reference – for functions, objects and arrays • JavaScript is loosely typed – does not require the data type declaration • Strongly typed languages – require data type declaration for variables Expressions & Operators

  9. Operators • Symbols used in expressions to manipulate operands • E.g. addition (+), multiplication (*), etc • JavaScript operators are unary or binary • Unary – requires a single operand • Binary – requires an operand before and after the operator • JavaScript operator types include: • Arithmetic – used for mathematical calculations • Assignment – assigns values to variables • Comparison – compares operands and returns a Boolean value • Logical – used for boolean operations • String – used on strings • Special – used for various purposes Expressions & Operators

  10. Arithmetic Operators • Used to perform mathematical calculations • Can be binary or unary • Binary – requires two operands • Unary – requires a single operand • Below are the arithmetic binary operators Expressions & Operators

  11. Arithmetic Operators… • Below are the arithmetic unary operators • The increment and decrement unary operators can be used as prefix or postfix operators • Prefix – placed before a variable • Variable is increased by one before value is used • E.g. ++myVariable, --myVariable • Postfix – placed after a variable • Variable is increased by one after value is used • E.g. myVariable++, myVariable-- Expressions & Operators

  12. Assignment Operators • Used for assigning a value to a variable • Below are the assignment operators Expressions & Operators

  13. Comparison Operators • Used to compare two operands for a returned value of true or false • Below are the comparison operators Expressions & Operators

  14. Conditional Operator • Executes one of two expressions, based on the results of a conditional expression • Syntax: condition ? expression1 : expression2 • If the condition is true, expression1 executes, else expression2 executes • E.g. document.write(4<5 ? ”Correct!” : ”Incorrect”); Expressions & Operators

  15. Logical Operators • Used for comparing two Boolean operands for equality • Below are the JavaScript logical operators Expressions & Operators

  16. String Operators • Used on strings • Two string operators used in JavaScript are: + and += • Concatenation operator (+) – used to combine two strings • E.g. “Hello “ + “World” • Compound assignment operator (+=) – used to combine strings • E.g. var greeting = “Hello “; greeting += “everyone”; Expressions & Operators

  17. String Escape Sequences • Combining the backslash (\) with other special characters for a special purpose • Several of the escape sequences are only recognized inside the <pre> tag • Below are some of the JavaScript escape sequences Expressions & Operators

  18. Special JavaScript Operators Expressions & Operators

  19. Operator Precedence • The order in which operations in an expression are evaluated • When operators are in the same precedence group, the order is determined by associativity (left-to-right or right-to-left) • Associativity – the order in which operators of equal precedence execute Expressions & Operators

More Related