JavaScript: More Syntax

Similar documents
JavaScript: More Syntax and Using Events

JavaScript: The Basics

Client-Side Web Technologies. JavaScript Part I

Web Site Design and Development JavaScript

PHP: The Basics CISC 282. October 18, Approach Thus Far

JavaScript: Coercion, Functions, Arrays

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

JavaScript for C# Programmers Kevin

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Chapter 2: Using Data

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

CS312: Programming Languages. Lecture 21: JavaScript

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

CGS 3066: Spring 2015 JavaScript Reference

CSC Web Programming. Introduction to JavaScript

CS1520 Recitation Week 2

JavaScript. The Bad Parts. Patrick Behr

COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Coding in JavaScript functions

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.

JavaScript: Introduction, Types

SPARK-PL: Introduction

Microsoft Visual Basic 2005: Reloaded

egrapher Language Reference Manual

Primitive Data Types: Intro

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

(Not Quite) Minijava

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

Background. Javascript is not related to Java in anyway other than trying to get some free publicity

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

JAVASCRIPT FOR THE C# DEVELOPER

JavaScript Syntax. Web Authoring and Design. Benjamin Kenwright

Chapter 7 Control I Expressions and Statements

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

PHP: More Syntax CISC 282 November 1, 2017

SYSC 2006 C Winter 2012

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

Outcomes Week 2 Overview Describe the inputs, activities, and outputs of each step in the software development life cycle. Describe arithmetic, relati

Compiler Errors. Flash CS4 Professional ActionScript 3.0 Language Reference. 1 of 18 9/6/2010 9:40 PM

Flow Control. CSC215 Lecture

Functional Programming. Pure Functional Programming

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

JavaScript CS 4640 Programming Languages for Web Applications

Chapter 3 Data Types and Variables

Microsoft Visual Basic 2015: Reloaded

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017

INF5750. Introduction to JavaScript and Node.js

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Chapter 2: Using Data

The Warhol Language Reference Manual

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Lecture 10. Overriding & Casting About

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

JavaScript: Sort of a Big Deal,

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

The PCAT Programming Language Reference Manual

JavaScript: The Good Parts. Douglas Crockford Yahoo! Inc.

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

Web Application Development

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

B. V. Patel Institute of BMC & IT 2014

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Database Programming with PL/SQL

B l o c k B i n d i n g s

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

Key Differences Between Python and Java

AJAX: Introduction CISC 282 November 27, 2018

JME Language Reference Manual

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

CIS 339 Section 2. What is JavaScript

3 The Building Blocks: Data Types, Literals, and Variables

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

JavaScript: Events, the DOM Tree, jquery and Timing

A control expression must evaluate to a value that can be interpreted as true or false.

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Iteration and Arrays Dr. Abdallah Mohamed

EECS1012. Net-centric Introduction to Computing. Lecture Introduction to Javascript

Angela Z: A Language that facilitate the Matrix wise operations Language Reference Manual

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

Ruby assign variable if nil. Ruby assign variable if nil.zip

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Petros: A Multi-purpose Text File Manipulation Language

Error Handling: SYNTAX

Scripting for Multimedia LECTURE 3: INTRODUCING JAVASCRIPT

PHPoC vs PHP > Overview. Overview

Rules and syntax for inheritance. The boring stuff

AJAX: The Basics CISC 282 November 22, 2017

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

Scope of this lecture. Repetition For loops While loops

CECS 189D EXAMINATION #1

Ruby: Introduction, Basics

JavaScript Basics. The Big Picture

PHPoC. PHPoC vs PHP. Version 1.1. Sollae Systems Co., Ttd. PHPoC Forum: Homepage:

Transcription:

JavaScript: More Syntax CISC 282 October 23, 2018 null and undefined What s the difference? null is synonymous with nothing i.e., no value, nothing there undefined is synonymous with the unknown i.e., this hasn t been set (yet?) All declared variables have undefined as an initial value until another value is assigned 2

true and false Booleans true and false are truly so What is falsey? Something that evaluates to false but isn't really String "" (empty) Number 0 NaN, null and undefined What is truthy? Something that evaluates to true but isn't really All non-empty strings All non-zero numbers Boolean Operators 3 Operator Result Description x y x y x OR y x && y x y x AND y!x x NOT x Only use Boolean operands! (x y) yields x if x is truthy; it yields y otherwise (x && y) yields x if x is falsey; it yields y otherwise 4

Testing Equivalence Operator Tests >, >= Greater than (or equal to) <, <= Less than (or equal to)!=, == (Not) equal to!==, === Strictly (not) equal to Standard equivalence operators performs conversion e.g., 4 == "4" true Strict equivalence operators take type into account e.g., 4 === "4" false 5 if Statements if(condition) if(condition) else if (condition) else or or if(condition) else if(condition) else if (condition) 6

for Loops for(initialvalue; condition; operation) Can declare a variable in initialvalue or not for(let i = 10; i > 0; i--) or let i = -1; for(i = 10; i > 0; i--) while loops 7 while(condition) or do while(condition); 8

Functions function name(parameter1,, parametern) return value; Function called with too many parameters? Extra parameters are ignored Can access full list using the arguments array Function called with too few parameters? Others are assigned values of undefined What if no return value is specified? Function returns undefined Undeclared Functions 9 function() Can create functions without names Also known as anonymous functions Can assign to a variable or use as an argument Why do this? Can be a shortcut when creating/assigning event handlers More on these later Required in a few situations 10

Variable Scope: Implicit All implicitly-defined variables are global variables Can be used in any subsequent function or statement Outside a function Inside a function The function must be called first Inside any block The block must be executed first x = 1; function scope() w = 2; for (y = 3; ) scope(); 11 Variable Scope: var Global variable if declared outside a function Local variable if declared inside a function Can only be used within that function Not restricted to declaring block (if applicable) var x = 1; function scope() var w = 2; for (var y = ) scope(); 12

Variable Scope: let Global variable if declared outside a function Local variable if declared inside a function Restricted to declaring block (if applicable) let x = 1; function scope() let w = 2; for (let y = ) scope(); Dialogs 13 alert(message) Displays message with an OK button confirm(message) Displays message with OK and Cancel buttons Returns true for OK, false for Cancel prompt(promptmsg, sampletext) Displays promptmsg with OK, Cancel and a text input box sampletext is optional; it is displayed in the input box Returns input for OK, null for Cancel 14

Best Practices Use semicolons to end statements They may be optional but they may cause issues if left out Explicitly declare all variables Avoid using global variables Comments are always important Use // for single lines Use /* */ for multiple lines 15