Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Introduction to Python
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
CS150 Introduction to Computer Science 1
JavaScript, Fourth Edition
JavaScript, Third Edition
The Information School of the University of Washington Oct 20fit programming1 Programming Basics INFO/CSE 100, Fall 2006 Fluency in Information Technology.
1 CS101 Introduction to Computing Lecture 38 String Manipulations (Web Development Lecture 13)
Variables & Data types Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer
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,
Javascript. Javascript Tools Javascript Console Javascript Console Debugger Debugger DOM Inspector DOM Inspector.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Chapter 2 Elementary Programming
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
ROUND 1 Name a method associated with class String 1.) 15 compareTo() 26 indexOf() 34 length() 2.) 3.) 4.) 3 toUpper() 7 substring() 11 charAt() 5.)
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
CS346 Javascript -3 Module 3 JavaScript Variables.
Strings, output, quotes and comments
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
Variables and Data Types Data (information we're going to store) – Numbers – Text – Dates What types of data can JavaScript process? How do we store it?
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Variables.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
Javascript Intro Instructor: Shalen Malabon. Lesson Plan Core Javascript Syntax Types and Objects Functions DOM Event Handling Debugging Javascript Smarter.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Expressions and Data Types Professor Robin Burke.
JavaScript Variables Like other programming languages, JavaScript variables are a container that contains a value - a value that can be changed/fixed.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
Chapter 2 Variables.
Chapter 6 JavaScript: Introduction to Scripting
JavaScript Objects.
Scope, Objects, Strings, Numbers
JavaScript Syntax and Semantics
Web Programming– UFCFB Lecture 19-20
JavaScript.
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 19 JavaScript.
WEB PROGRAMMING JavaScript.
Chapter 2: Basic Elements of Java
INFO/CSE 100, Spring 2005 Fluency in Information Technology
Chapter 2 Variables.
T. Jumana Abu Shmais – AOU - Riyadh
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Variables Kevin Harville.
Chapter 2 Variables.
CGS 3066: Web Programming and Design Fall 2019
Presentation transcript:

Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman

Objectives Declare a simple variable Recognize valid and invalid variable names Assign a simple value to a variable Begin to understand the concept of scope Create a number

More Objectives Create a string Escape a problematic or meaningful character within a string Create a Boolean Perform arithmetic with numbers Format numbers

More Objectives Use constants and methods in the Math object Access the characters in a string Manipulate strings Convert between numbers and strings

A Simple Statement var myVar = 'easy peasy';

Declaring Variables var myVar; var thing1, thing2;

[GLOBAL] globalVar A Quick Glance at Scope var globalVar; function f() { var localVar; // Can also use globalVar here! } f() localVar

Variable Names Must start with a letter, the underscore, or a dollar sign Can contain any combination of letters, underscores, and numbers Cannot use spaces, hyphens, or punctuation Cannot be a reserved word Are case-sensitive

Valid Names fullName num _myVar $myVar price1

Assigning Values var num; num = 23; var str = ‘Hello, world!’; var num = 23, str = ‘Hello, world!’;

Simple Value Types Numbers Strings Booleans

Numbers Never quoted Can include an optional single decimal Can have an initial +/- Do not contain commas Only a single number type in JavaScript.

Arithmetic + - * / % += -= *= /= var n = 1; n *= 4; // n = 4

Formatting Numbers var n = ; n.toFixed(); // 123 n.toFixed(1); // 123.5

Example var total; var quantity = document.getElementById('quantity').value; var price = document.getElementById('price').value; var tax = document.getElementById('tax').value; var discount = document.getElementById('discount').value; total = quantity * price; tax /= 100; tax++; total *= tax; total -= discount; // Format the total: total = total.toFixed(2);

The Math Object PI E abs() ceil() cos() floor() max() min() pow() round() random() sin() var area = Math.PI * radius * radius; var volumn = 4/3 * Math.PI * Math.pow(radius, 3);

Strings Always quoted Can be empty Can use single or double quotation marks

String Characters length charAt() indexOf() lastIndexOf() var name = 'Larry Ullman'; name.length; // 12 name.charAt(11); // n name.indexOf('a'); // 1 name.indexOf('man'); // 9 name.lastIndexOf('a'); // 10

Slicing Strings var language = 'JavaScript'; language.slice(4); // Script language.slice(0,4); // Java language.slice(0,-6); // Java language.slice(-6); // Script

Escaping Characters 'I\'ve got an idea.' "Chapter 4, \"Simple Variable Types\"" \n \r \\

Concatenation var message = 'Hello'; message = message + ', World'; message += '!';

Booleans true false

Type Conversions parseFloat() parseInt() toString() var shipping = document.getElementById('shipping').value; // String, say '4.50' var total = 25.00; total += shipping; // String! ' ' total += parseFloat(shipping); // Works! 29.50

Special Values null undefined NaN Infinity