CIS 375—Web App Dev II JavaScript I
2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight ____________ language. JavaScript can be inserted into an _______ page. JavaScript is used to make web pages more dynamic and ___________. JavaScript is NOT Java, but shares some of the same ________.
3 Simple JavaScript Inserting simple JavaScript into a simple web page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " document.write("Hello World!")
4 Handling Older Browsers You should write code like this in case the user has a browser before version 3.0: <!-- document.write("Hello World!") //--> A newer browser will ignore the <!-- and the ____. An older browser will ignore the, and everything between the <!-- and the _____.
5 JavaScript Where To… Scripts in the body section will execute when the page ______, in the head section when ________. function message(){ alert("This alert box was called with the onload event") }
6 JavaScript in an External File Scripts can be stored in an external file with a _____ extension. The contents of myfile.js might be the following: document.write("This script is external")
7 Variables Variables are used to _______ data. Rules for variable names: Variable names are _______ sensitive They must begin with a letter or the _________ character Example: var name = “Richard Johnson" Variables declared in a function are local to that function. They are destroyed when the function is ________. Variables declared outside a function are available to all functions on the page. They are destroyed when the page is _______.
8 Example of Variable Use <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " var name = “Richard Johnson" document.write(name) document.write(" "+name+" ") This example declares a variable, assigns a value to it, and then displays the variable. Then the variable is displayed one more time, only this time as a heading.
9 JavaScript Operators A complete listing of JavaScript operators can be found at These are identical to ______ operators.
10 JavaScript Functions A function contains some code that will be executed by an _______ or a call. Here is how to call JavaScript’s alert method: alert("This is an alert!")
11 Example of Function Call function myFunction(){ alert("HELLO") } By pressing the button, a function will be called. The function will alert a message.
Function w/ Arguments, Return <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " function total(numberA, numberB){ return numberA + numberB } document.write(total(2,3))