Javascript Intro Instructor: Shalen Malabon. Lesson Plan Core Javascript Syntax Types and Objects Functions DOM Event Handling Debugging Javascript Smarter.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 COMM 1213 H1 COMP 4923 X1 JavaScript 1 (Readings: Ch. 10, 11 Knuckles)
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 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.
Tutorial 10 Programming with JavaScript
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.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Introduction to scripting
Javascript and the Web Whys and Hows of Javascript.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Lesson 19. JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
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.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Syntax, how to use it in a HTML document
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Server versus Client-Side Programming Server-SideClient-Side.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
1 JavaScript in Context. Server-Side Programming.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
REEM ALMOTIRI Information Technology Department Majmaah University.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
Module 1 Introduction to JavaScript
Programming Web Pages with JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript an introduction.
Objectives Insert a script element Write JavaScript comments
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript: Introduction to Scripting
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Javascript Intro Instructor: Shalen Malabon

Lesson Plan Core Javascript Syntax Types and Objects Functions DOM Event Handling Debugging Javascript Smarter Form UI Enhancement Javascript Best Practices Advance Javascript Features

What you should know HTML and CSS

Javascript HTML- mark up language(content) CSS- style sheet language(presentation) Javascript – scripting language(behavior) Javascript is a language that's typically used inside websites, in order to manipulate the HTML output on the screen, pull in data from elsewhere, and do calculations.

JavaScript is limited Can’t access local files Can’t directly access the database Can’t access hardware(USB,etc)

Javascript is interpreted, not compiled. Javascript is case sensitive. Javasript is whitespace insensitive.

Javascript- is a client-side language

o JavaScript is *not* a "light" version of Java, but its own full- featured programming language, sharing some syntax with Java but also different in many ways

The Element

Statements -separate instructions or commands to say a piece of what you want or code will do. -terminated by a semi-colon

Activity 1 Simple Page Simple HTMLPage This is very simple HTML page It's about as basic as they come. It has : An h1 tag Two paragraphs An ordered list alert( "Hello World!" );

Where to put javascript? Position of the code matters

write() and writeln() methods: - Use to display text in a Web browser when the document is first rendered -the only difference between the write() and writeln() is that the writeln()method adds a line breaks after the line of text. Line breaks however are only recognized inside the element.

Case sensitivity in Javascript Like XHTML, JavaScript is case sensitive, and within javascript code, object names must always be all lower case. The statement: Document.write(“Welcome to Nashville”); Causes an error message because the JavaScript interpreter Cannot recognize an object named with an uppercase D.

Adding Comments Comments- are various types of remarks including the name of the program, your name and the date you created the program, notes to yourself or instructions to future programmers who may need to modify your work. Line comments: hides a single line of code. // This line comment takes up an entire line Block comments /* This line is a part of block comment. This line is also part of block comment. /*

Including element for each code section Multiple Script Sections First script section document.write(“ Output from the first script section ” ); Second script section document.write(“ Output from the second script section ” );

Logic and Debugging Logic – refers to the order in which various part of a program run or execute. Bug- any error in a program that causes it to function incorrectly, whether because of incorrect syntax or flaws in logic. Debugging – is the act of tracing and resolving errors in a program.

Using the Browser Console Javascript is usually evaluated after being included in a website, but modern browsers often come with a console that lets you run arbitrary JavaScript and see the results. The console can be used for quick experimentation, like for the upcoming concepts. FirefoxChrome Download the Firebug extension for Firefox.Go to Developer->Tools->Console or press CTRL+SHIFT+J.

Basic Variables Use var to declare a variable. Its initial value will be undefined. var x; It will work if you don't use var, but then it will become a global variable, which you usually don't want. You can later initialize it: x = 5; Or you can declare and initialize all at once: var x = 5;

var name; name name = “jasmine”; undefined jasmine

Basic Data Types Variables are loosely typed. They can be assigned to any data type, and can later be re-assigned to different data types. The primitive data types in Javascript are string, number, and boolean, undefined, and null: var x; x = "6"; x = 2 + 2; x = false; x = null; The complex data types are Arrays or Objects (covered later). Everything in JS is one of these types. **activity1

Numbers All numbers are 64 bit floating point - there's no differentiation between an int/float/double type. The standard operators for numbers work in Javascript: var x = 2 * 3; var y = x / 4; var z = x - y; When an operation doesn't result in a valid number, it returns NaN or in case of 1/0, Infinity. There are various utility functions in the Math library: var x = Math.abs(-454); var y = Math.pow(2, 3);...

Strings Strings are immutable, but a new string can be created easily with concatenation: var x = "hello"; var y = "world"; var z = x + " " + y; x += "!"; Single quotes and double quotes are the same: var x = "hi"; var x = 'hi'; Single quotes can be used inside double quotes, & vice versa: var x = "then he said, 'thats awesome!'"; var y = 'then he said, "thats awesome!"'; ** Activity 2

Strings Numbers Strings can be converted to numbers by doing simple math on them: var x = "43.232" * 1; Use parseFloat to turn a string into a number: var x = parseFloat("43.232"); Use parseInt to return a number with no digits after the decimal: var x = parseInt("43.232"); Numbers can be converted to strings with a formal cast, or just by appending an empty string. var x = 23 + ""; var x = String(23);

String Methods Strings have many native helper methods: var greeting = "Hello there"; greeting.charAt(0); // "H" - String indices are 0-based greeting.toUpperCase(); // "HELLO THERE" This indexOf function returns the start index of the first occurrence of a given character or substring, or -1 if not found. greeting.indexOf("e"); // 1 greeting.indexOf("there") // 6 greeting.indexOf("E") // -1 Method calls can be chained in Javascript: greeting.toUpperCase().indexOf("E") ** Activity 2

String Methods The slice method is a handy way to create substrings. slice(start, end) returns a copy of the string beginning at start and extending up to but not including end: 'Hello'.slice(1, 3); // "el" If no end is specified, it copies up to the end of the string: 'Hello'.slice(2); // "llo" The replace method is a handy way to create a new string by replacing a substring with another substring: 'hi, hi'.replace('hi', 'bye'); // "bye, hi"

Using in a Webpage JavaScript can be embedded inside script tags on a page: var x = "Hello World"; alert(x); Javascript can also be in external files, and referenced in a page:

Outputting to HTML The absolute simplest way to modify the HTML of a page using JavaScript is with the document.write method: document is a predefined browser variable that always points to the current HTML document. The write method will let us insert text (or HTML) into the document immediately following the element: document.write("Hello World"); Note:The inserted content will not appear in the browser's "view source" window (try it out), but it will appear in the page model accessible via JavaScript (more on that later).

Debugging with Browser Consoles The browser console will output any errors it encounters while running JS on the current page. The most common errors are trying to use functions or variables that don't exist. Try the following in an HTML file: alertt("alertt doesn't exist"); The console status bar will display "1 Error", and you can open up the console for more information. It will often point to the line of code that caused the error, and show a trace of the functions called before the error was called. You can also use console.log() to write out information to the console from within your web page's JS.

Arithmetic operators: + - / * Shorthand score= score + 10;score+=10; score= score - 10;score-=10; score= score / 10;score/=10; score= score * 10;score*=10;

Operator precedence result = 5+5 *10; Ans= 55

symbols ( ) parentheses [ ] brackets { }braces Operators: <!= >=== ==>= <=