Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript.

Similar presentations


Presentation on theme: "JavaScript."— Presentation transcript:

1 JavaScript

2 What is JavaScript JavaScript is the scripting language of the Web!
JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more. JavaScript is the most popular scripting language on the internet.

3 What is JavaScript JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language A JavaScript consists of lines of executable computer code A JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation) Everyone can use JavaScript without purchasing a license

4 Are Java and JavaScript the Same?
NO! Java and JavaScript are two completely different languages in both concept and design! Java (developed by Sun Microsystems) is a powerful and much more complex programming language - in the same category as C and C++.

5 What can a JavaScript Do?
JavaScript gives HTML designers a programming tool JavaScript can put dynamic text into an HTML page JavaScript can react to events JavaScript can read and write HTML elements JavaScript can be used to validate data JavaScript can be used to create cookies

6 How to Put a JavaScript Into an HTML Page
<html> <body> <script type="text/javascript"> document.write("Hello World!") </script> </body> </html>

7 Where to Put the JavaScript
JavaScripts in the body section will be executed WHILE the page loads. JavaScripts in the head section will be executed when CALLED.

8 VARIABLES

9 JavaScript Variables A variable is a "container" for information you want to store. A variable's value can change during the script. You can refer to a variable by name to see its value or to change its value. Represents a value stored in a memory

10 Numeric Variables Values that hold number

11 String Variables Values that hold words or combination of letters

12 Boolean Variables Represents a state or condition as being true or false

13 Rules for variable names:
Variable names are case sensitive They must begin with a letter or the underscore character Do not place any space or punctuation in the name Avoid naming variables with reserved words Reserved words are predefined words that have special meaning to JavaScript

14 Examples of valid and invalid variable names
idnumber Id number Cust_ID Cust.ID Major *Major Year2000 2000 _continue Continue

15 Declaring a variable Variables are declared the first time they are used by inserting the word var before the variable name, followed by an equal ( = ) sign

16 Declare a Variable You can create a variable with the var statement:
var strname = some value You can also create a variable without the var statement: strname = some value

17 Lifetime of Variables When you declare a variable within a function, the variable can only be accessed within that function. When you exit the function, the variable is destroyed. These variables are called local variables. You can have local variables with the same name in different functions, because each is recognized only by the function in which it is declared. If you declare a variable outside a function, all the functions on your page can access it. The lifetime of these variables starts when they are declared, and ends when the page is closed.

18 Literals While a variable is used to store data or values, a literal is a constant value that does not change. A literal is an actual number or character text, rather than a calculated result or value from input from a keyboard. Numeric= number e.g var width=3 String = character or text value e.g var browsertype=“Netscape”

19 Expressions and Operators
Is a formula or a way to assign values to variables Average=totalvalue/Count >>>shows an expression that might be used in simple math problems

20 Concatenation Used to join string literals or variables to get as one variable

21 Functions Is a way to write several lines of script and used them repeatedly as needed.

22 Conditional Statements
In JavaScript we have the following conditional statements: if statement if...else statement if...else if....else statement switch statement


Download ppt "JavaScript."

Similar presentations


Ads by Google