Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type:  <script language =“Javascript”  <!-- hide script.

Slides:



Advertisements
Similar presentations
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Advertisements

©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
JavaScript, Third Edition
String Escape Sequences
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
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.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
A First Book of ANSI C Fourth Edition
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
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.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Numeric Types, Expressions, and Output ROBERT REAVES.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
C++ Programming: Basic Elements of C++.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
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.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
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.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Primitive Variables.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Data Types Declarations Expressions Data storage C++ Basics.
Chapter 2 Variables.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
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.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 2 Variables.
Chapter 6 JavaScript: Introduction to Scripting
Data Types, Variables & Arithmetic
BASIC ELEMENTS OF A COMPUTER PROGRAM
ITEC113 Algorithms and Programming Techniques
Data Types, Identifiers, and Expressions
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2 Variables.
CSE 100 Data Types Declarations Displays.
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Chapter 2: Introduction to C++.
Data Types and Expressions
Primitive Types and Expressions
Chapter 2 Variables.
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

Javascript Essentials

How do I write it??  Start Homesite  Between the start and end BODY tags type:  <script language =“Javascript”  <!-- hide script from old browsers  alert('Welcome to my Web Site!');  //-->   Save and Browse *

Data “Types” Declarations Expressions Data Storage Javascript Basics

Javascript Data Types  String  Integral  Floating - default type -ordinal numbers -Use parseInt() -real numbers -Use parseFloat()

Characters and Integers  char(1 Byte) 256 possibilities, ASCII characters enclosed in single quotes: ‘B’  int (2 or 4 Bytes) no decimal points no commas no special signs ($, ¥, ‰) * * *

Floating Point Number Data Types  Floating point numbers: signed or unsigned with decimal point  Types: differ in amount of storage space; varies with machine   float (single precision)  double  long double * * *

Variables   a place to store information  contents of a location in memory  *  has an address in RAM  uses a certain number of bytes Name Type Location num1 int 1000

Identifiers  Valid examples:  xnum1num2 name rowc237indextax_rate * * * Not valid: 1num bye[a] tax-rate tax rate OK: newPos newpos (beware of this!)

Identifiers

Rules for Naming Identifiers  Can contain digits, letters, underscores  NO SPACES  Begin identifier name with a letter  Limit Identifiers to 20 characters * * *

Variable Definition  Associates an identifier with its use  Can be done with an assignment  or must be done with documentation Identifiers should have meaningful names. - Reduces confusion - Very few one letter names are acceptable: i, j, k, l, x, y, z (others?) - Two letter names? PI * *

Variable Definition  var identifier_list;  var i, k;  var taxRate = 0.087;  var len = 10, wid =20; * * var name = “Joe”; alert('Welcome to my Web Site!‘+ name);

Literals & Constants Literals: 'Y', 23.4, -1, "Hello" typed directly into the program as needed ex. y = 23.4pi =  Literal values are stored in anonymous memory addresses by the compiler * * *

Operators  An operator is a symbol that causes the compiler to take an action. * Categories: mathematical assignment boolean/logical etc.

Binary Arithmetic Operators  addition+  subtraction   multiplication *  division /  modulus % Unary Minus operator: x = -3; y = -x; *

Arithmetic Operators

Increment and Decrement

Arithmetic Expressions Syntax operand operator operand  Example — * / % 3 *

Integer Division & Modulus 12/3 14/3 12%3 14%3  The modulus operator yields the remainder of integer division. *

Modulus Examples  The modulus operator yields the remainder of integer division.  18 % 4 is 2 13 % 4 is 1 17 % 3 is 2 35 % 47 is % 6 is 0 24 % 4 is 0 4 % 18 is 4 0 % 7 is 0 * * Requires floating point division! Not the same. 12 % 2.5 error 6.0 % 6 error

Operator Precedence

Order of Operations * 4 is ?  Show associativity to clarify. ( ) * 4 is ( 3 * 4 ) is 20 * P M D A S from left to right ( ) * / + -

Order of Operations  Expression Value 10 / 2 * 3 10 % / * 2.0 / 4.0 * * 2.0 / (4.0 * 2.0) / (4.0 * 2.0) * * * * *

Evaluation Trees i i 10 / 2 * 3 * 10 % / 2 i i i 5.0 * 2.0 / 4.0 * 2.0 r r r 5 * 2 / (4.0 * 2.0) i r r

Evaluation Trees 5.0 * 2.0 / 4.0 * / (4.0 * 2.0) (5 + 2) / (4.0 * 2.0) i r r r r r r r r

Beware!  The asterisk is required to indicate multiplication.  validinvalid 5*(8+3) 5(8+3)  (x-y)*(x+y) (x-y)(x+y)

Assignment Operator The assignment operator (=)causes the operand on the left to take on the value to the right side of the statement.  This operator assigns from right to left. validinvalid name = “Sue”“sue” = name *

Assignment Statement Syntax:variable = expression;  Examples: quiz1score = 14; lname = “Newman”; fname = “Alfred E.”; wname = fname + “ “ + lname; Do NOT use the word equals here. Use is assigned to or gets. *

 4a. Look up balance value 4b. Look up deposit value 4c. Add values 4d. Store result in balance * Storage Locations 1. deposit = 234; 2. balance = 1000; 3. balance = balance + deposit;

Storage Locations q e w 6 bytes of storage deposit balance After assignment: balance = balance + deposit; r t y\

Assignment Operators

String Concatenation

Relational and Boolean Operators

Conditional Statement (if)