2440: 211 Interactive Web Programming Expressions & Operators.

Slides:



Advertisements
Similar presentations
Chapter 17 Fundamental Concepts Expressed in JavaScript.
Advertisements

Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
PHP Introduction.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fundamental Concepts Expressed in JavaScript Get with the Program lawrence.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
Chapter 2: Introduction to C++.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Objectives You should be able to describe: Data Types
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
A Review of Programming and C++
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
Chapter 2: Using Data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
C++ Programming: Basic Elements of C++.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
CHAPTER 4 GC 101 Data types. DATA TYPES  For all data, assign a name (identifier) and a data type  Data type tells compiler:  How much memory to allocate.
CS346 Javascript -3 Module 3 JavaScript Variables.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 JavaScript.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 6 JavaScript: Introduction to Scripting
JavaScript, Sixth Edition
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
Fluency with Information Technology
Overview: Programming Concepts
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 17 JavaScript.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Basics of ‘C’.
Chapter 2: Basic Elements of Java
JavaScript Data Concepts
T. Jumana Abu Shmais – AOU - Riyadh
elementary programming
Chapter 2: Introduction to C++.
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

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 & Operators3 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 & Operators4 JavaScript Keywords abstractdoifprotectedtry booleandoubleimplementspublictypeof breakelseimportreturnvar byteenuminshortvoid caseexportinstanceofstaticvolatile catchextendsintsuperwhile charfalseinterfaceswitchwith classfinallongsynchronized constfinallynativethis continuefloatnewthrow debuggerfornullthrows defaultfunctionpackagetransient deletegotoprivatetrue

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

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

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

Expressions & Operators8 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 & Operators9 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 & Operators10 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 OperatorNameDescription +Addition Adds two operands -Subtraction Subtracts one operand from another *Multiplication Multiplies two operands /Division Divides one operand by another %Modulus Divides one operand by another and returns the remainder

Expressions & Operators11 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-- OperatorNameDescription ++Increment Increases an operand by a value of one --Decrement Decreases an operand by a value of one -Negation Returns the opposite value (negative or positive) of an operand

Expressions & Operators12 Assignment Operators  Used for assigning a value to a variable  Below are the assignment operators OperatorDescriptionExample Equivalent to = Assigns the value of the expression on right to the expression on the left x = y += Adds two expressions x += y x = x + y -= Subtracts the expression on the right from the expression on the left x -= y x = x - y *= Multiplies two expressions x *= y x = x * y /= Divides the expression on the left by the expression on the right x /= y x = x / y %= Calculates the remainder from dividing the expression on the right from the expression on the left x %= y x = x % y

Expressions & Operators13 Comparison Operators  Used to compare two operands for a returned value of true or false  Below are the comparison operators OperatorNameDescription ==Equal Returns true if the operands are equal === Strict equal Returns true if the operands are equal and of the same type != Not equal Returns true if the operands are not equal !== Strict not equal Returns true if the operands are not equal or not of the same type > Greater than Returns true if the left operand is greater than the right operand >= Greater than or equal Returns true if the left operand is greater than or equal to the right operand < Less than Returns true if the left operand is less than the right operand <= Less than or equal Returns true if the left operand is less than or equal to the right operand

Expressions & Operators14 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 & Operators15 Logical Operators  Used for comparing two Boolean operands for equality  Below are the JavaScript logical operators OperatorNameDescriptions &&And Returns true if both the left and right operand return a value of true ||Or Returns true if either the left or right operand or both return a value of true !Not Returns true if an expression is false

Expressions & Operators16 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 & Operators17 String Escape Sequences  Combining the backslash (\) with other special characters for a special purpose  Several of the escape sequences are only recognized inside the tag  Below are some of the JavaScript escape sequences Escape Sequence Character \t Horizontal tab \bBackspace \n New line \v Vertical tab \’ Single quote \” Double quote \\Backslash

Expressions & Operators18 Special JavaScript Operators CharacterNameMeaning // Double forward slashes Marks the beginning of a comment ( ) Opening and closing parenthesis Used in a method header { } Opening and closing braces Encloses a group of statements “ “ Double quotation marks Encloses a string of characters ‘ ‘ Single quotation marks Encloses a single character ;Semicolon Marks the end of a programming statement /* */ Forward slash and asterisk Marks the beginning and ending of a comment

Expressions & Operators19 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