Introduction. The scripting language most often used for client-side web development. Influenced...

10
JAVASCRIPT Introduction

Transcript of Introduction. The scripting language most often used for client-side web development. Influenced...

Page 1: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

JAVASCRIPTIntroduction

Page 2: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

OVERVIEW

The scripting language most often used for client-side web development.

Influenced by many programming languages, easier for nonprogrammers to work with.

Best known for its use in website development.

Unrelated to Java programming -- although both have a common C syntax

Supports all the structured programming syntax in C, Java, C#. – variables, conditionals, repetition structures, data structures, classes

Page 3: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

USE IN WEBPAGES Primary use is to write function that are embedded

in HTML pages: Examples:

popping up a new window with control over size, position, attributes.

Validation of web form input values to make sure they are acceptable before submitting to server.

Changing images as a mouse moves over them.

The JavaScript interpreter interprets JavaScript source code and execute the script accordingly. not a compiled language like C or C++

Most common host environment for JavaScript is a web browser

Page 4: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

OVERVIEW JavaScript is object based Client side scripting – runs on browser,

not on serverDon't need to send and retrieve data to the

serverSaves time

Does not need to be compiledScript interpretation done by browser

Page 5: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

USING <SCRIPT> TAGS To tell html you will be using JavaScript do

this:

<script type=”text/javascript”> …. </script>

Everything between the opening and closing tags is JavaScript

Browser treats code as scripting language not html

Place <script> inside head tag, the browser interprets <head> first so the JavaScript will execute before the body

Page 6: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

WHERE TO PUT <SCRIPT> If <script> placed in <head> tag, it gets

run first If <script> placed in <body> tag, runs in

order it was placed JavaScript can be placed in an external

file

<script type=”text/javascript” src=“myJavaScript.js” </script>

External JavaScript files end with .js extension

Page 7: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

FIRST SCRIPT<script type="text/javascript">

document.write(“hello world!");

alert(‘hello world’);

</script>

“hello world” is a character string - a string of characters contained between double or single quotes

parentheses following the name of the method containing the arguments that the method requires to perform its task.

Every statement should end with a semicolon (not required but a programming standard).

JavaScript is case sensitive method write() – write a line of text

Page 8: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

COMMENTS Good practice to comment your code –

explain what your code does Comments – ignored by the browser One line comment

// This is a one line comment Multi-line comment

/* this is a multi-line commentI have a lot to explain

*/

Page 9: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

TRACKING DOWN ERRORS

In Chrome – JavaScript Debugger is F12 or CTRL, shift J

In Firefox, use the error console (CTRL, Shift, J) Provides clear description of errors Identifies the line in your code where error

occurred

Page 10: Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.

TRY Fade in practice

chapter1 – 1.html