The <script> Tag

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
14/11/11.  These words have special meanings in themselves  These should NOT be used as Identifiers.  For example:  Break, do, function, case, else,
12-Jun-15 JavaScript Language Fundamentals I. 2 About JavaScript JavaScript is not Java, or even related to Java The original name for JavaScript was.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
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
JavaScript, Third Edition
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 3: Data Types and Operators JavaScript - Introductory.
1 JavaScript 1. 2 Java vs. JavaScript Java –Is a high level programming language –Is platform independent –Runs on a standardized virtual machine.
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?
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Javascript. What is JavaScript? Scripting (interpreted) language designed for the web Beware: JavaScript is case sensitive.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Server versus Client-Side Programming Server-SideClient-Side.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
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.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Build in Objects In JavaScript, almost "everything" is an object.
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
JavaScript is a programming language designed for Web pages.
Introduction to Scripting
JavaScript Syntax and Semantics
JavaScript.
Chapter 19 JavaScript.
JavaScript and Ajax (Expression and Operators)
JavaScript an introduction.
Web Systems Development (CSC-215)
Exercises on JavaScript & Revision
Chapter 6 Variables What is VBScript?
Chapter 8 JavaScript: Control Statements, Part 2
Introduction to JavaScript for Python Programmers
INFO/CSE 100, Spring 2005 Fluency in Information Technology
The Web Wizard’s Guide To JavaScript
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Web DB Programming: PHP
Web Programming Language
The Internet 11/15/11 Handling Data in JavaScript
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Tutorial 10 Programming with JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
PHP an introduction.
CIS 136 Building Mobile Apps
Web Programming and Design
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

The <script> Tag The <script> tag (<script>….</script>) in all major browsers interprets contents as JavaScript unless one of the following occurs Inclusion of language attribute <script language=“VBS”>….</script> Inclusion of type attribute <script type=“text/javascript”>….</script> The type attribute is W3C recommended, it makes the language more common and in many ways more useful

<script> tag is used to delimit the script code from the HTML The script tag causes the browser’s JavaScript interpreter to be invoked, the script run and any output produced The browser is considered the “host” environment There are other hosts for JavaScript and its variants

Location of Code JavaScript may be placed at three places In the <head> element Place scripts to be called or when event is triggered here Ensures script is loaded before called <html> <head> <script type=“text/javascript”> //script statements </script> </head>

Location of Code In the <body> element Place scripts to be executed when the page loads here Script generates some or all of the contents of the page <body> <script type=“text/javascript”> //script statements </script> </body>

Location of Code External to the HTML file <head> <script src=“myfile.js”> </script> </head> Could be in <head> or <body> External script should not contain <script> tag

Statements A script is made up of individual statements Javascript statements are terminated by returns or semi-colons same as So, prefer to use semi-colons x=x+1 alert(x) //throws an error while x=x+1; alert(x); //does not x=x+1 alert(x) x=x+1; alert(x);

Basic data types in JavaScript Every variable has a data type that indicates what kind of data the variable holds Basic data types in JavaScript Strings Strings may include special escaped characters Numbers (integers, floats) Booleans (true, false) ‘null’ and ‘undefined’ are also considered as types

JavaScript is a weekly typed language meaning that the contents of a variable can change from one type to another Example x = “hello”; x = 5; x=false; While week typing seems beneficial to a programmer it can lead to problems

Arrays An ordered set of values grouped together with a single identifier Defining Arrays var myArray = [1,5,1968,3]; var myArray2 = [“fakhar”,true,3,-47.2]; var myArray3 = new Array (); var myArray4 = new Array (10);

Arrays Arrays in JavaScript are 0 based We access arrays by index values var myArray = [1,5,1968,3]; myArray[3] is ‘3’ Difference Array types (composite type as well) are reference types, so problem of aliasing is there var firstArray = [“Mars”, “Jupiter”, “Saturn” ]; var secondArray = firstArray; secondArray[0] = “Neptune”; alert(firstArray); // it has been changed

Operators Basic Arithmetic Increment decrement Comparison Logical + , - , / , * , % Increment decrement ++, - - Comparison < , > , >= , <= , != , == , === (type equality) Logical &&, ||, ! Bitwise Operators & , | , ^ String Operator + (used for concatenation) document.write(“JavaScript” + “is” + “great!”);

Type Conversion Converting one type of data to another is both useful and a source of numerous errors in JavaScript var x = “10” – 2 ; //result is 8 var x = “2” – “2” ; //result is 0 var x = “2” + “2” ; //result is “22”

Control Statements If Switch While Do-while For Continue Break For (in)

Labels and Flow Control A label can be used with ‘break’ and ‘continue’ to direct flow control more precisely