JavaScript Errors What Could Possibly Go Wrong WCPGW- A statement of unbridled optimism and also an immediate trigger for Murphy's Law. Generally uttered.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

Topics Introduction Types of Errors Exceptions Exception Handling
Introducing JavaScript
Javascript Code Quality Check Tools Javascript Code Quality Check Tools JavaScript was originally intended to do small tasks in webpages, but now JavaScript.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
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.
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
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.
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
Javascript and the Web Whys and Hows of Javascript.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
JavaScript An Introduction.
Generations of Programming Languages First generation  Machine Language Second Generation  Assembly Language Third Generation  Procedural language such.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
Neal Stublen Course Road Map  Create web page layouts using CSS  Manage CSS  Test website validity  Create navigation menus using.
Introduction to JavaScript Gordon Tian
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CPS120: Introduction to Computer Science Decision Making in Programs.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Basic Java Syntax COMP 401, Spring 2014 Lecture 2 1/14/2014.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
Conditional Statements © Copyright 2014, Fred McClurg All Rights Reserved.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
1 JavaScript in Context. Server-Side Programming.
JavaScript Challenges Answers for challenges
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
© Oxford University Press All rights reserved. CHAPTER 10 THE PREPROCESSOR DIRECTIVE.
Javascript Intro Instructor: Shalen Malabon. Lesson Plan Core Javascript Syntax Types and Objects Functions DOM Event Handling Debugging Javascript Smarter.
Debugging No readings. 2 What's The Proper Indentation? function max(x,y) { if (x
Expressions and Data Types Professor Robin Burke.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Tarik Booker CS 120 California State University, Los Angeles.
REEM ALMOTIRI Information Technology Department Majmaah University.
Programming Web Pages with JavaScript
JavaScript: Good Practices
JavaScript is a programming language designed for Web pages.
Introduction to C# Applications
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Modern JavaScript Develop And Design
JavaScript Functions.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
DHTML.
JavaScript Introduction
Objectives Insert a script element Write JavaScript comments
Conditions and Ifs BIS1523 – Lecture 8.
WEB PROGRAMMING JavaScript.
JavaScript Basics What is JavaScript?
Chapter 4 - JavaScript Events, Objects, & Functions
Web Programming and Design
Using Your Resources Correctly!
Presentation transcript:

JavaScript Errors What Could Possibly Go Wrong WCPGW- A statement of unbridled optimism and also an immediate trigger for Murphy's Law. Generally uttered at meetings followed within seconds by a cascade of unexpected and horrid consequences. Example: What are you doing today? Cleaning windows on the World Trade Centre, "What could possibly go wrong?"

Common Errors Discussion: It is not a matter of “if” you make an error in JavaScript but “when”, so it is savvy to be prepared. All JavaScript errors will be unique to your code, however, there are a number of common issues that most JavaScript programmers will encounter. It is helpful to be aware of these problem categories. 2

JavaScript Code Quality Tools JSHint: Helps detect errors and potential problems in code: JSLint: Code checker that finds common mistakes in scripts: 3

Using Eclipse to Catch Errors 1.Make sure Eclipse Project is configured as a JavaScript Project. Right-click on the project name: Configure -> Convert to JavaScript Project 2.Validate the JavaScript File. Right- click on the file name: Validate 4

Syntax Errors Discussion: Syntax errors often involve something that is missing like a parenthesis, curly brace, or a semi-colon. Errors: function myFunction( { // missing ")" // missing double quote on string console.log("You called myFunction); } window.onload = function() { myFunction(); } // missing semi-colon on statement 5 syntaxErrors.html

Calling Non-existing Function Discussion: It is easy to make a mistake in capitalization or spelling of variables and function names. These errors will not show up in Eclipse or the console until run-time. Errors: function myFunction() { console.log("You called myFunction"); } window.onload = function() { myfunction(); // incorrect capitalization }; 6 callNonExistingFunct.html

Attribute or Method Typo Discussion: In addition, any predefined attribute or method must be spelled and capitalized properly. Common Errors: // strings can not have a return in the middle var einstein = "Great ideas often receive violent opposition from mediocre minds."; // error // attribute misspelled. should be "einstein.length" var size = einstein.len; // error // attribute "einstein.length" is not method var chars = einstein.length(); // error // should be "getElementById()" with "Id" not "ID" var title = document.getElementByID("mainTitle"); // error // should be "getElementsByTagName()" with "Elements" plural var para = document.getElementByTagName("p"); // error 7 methodTypo.html

Use Element Before Loaded Discussion: Accessing DOM elements before they are loaded can be prevented by calling script from window.load() method. Errors: // using element before it is loaded // make sure DOM is loaded using window.load() var myImage = document.getElementById( "up" ); console.log( myImage.getAttribute( "src" ) ); 8 useBeforeLoaded.html

Assignment vs Equality Discussion: Specifying an assignment inside a conditional statement is a common error and one that may be difficult to track down.. Errors: var enrolled = 7; // should be "==" instead of "=" if ( enrolled = 0 ) { // false console.log( "Session cancelled." ); } else { console.log( "Session scheduled." ); } 9 assignVsEquality.html

Call Argument and Parameter Mismatch Discussion: A parameter that does not have an associated argument in the call statement will have a value of “undefined”. The arithmetic of an “undefined” value will result in a “NaN”. Errors: // argument mismatch between call and definition // three parameters in function definition function calculateSum( a, b, c ) { console.log( "c = " + c ); return( a + b + c ); } // two arguments in function call var result = calculateSum( 500, 1000 ); console.log( result ); 10 paramMismatch.html