Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript Syntax, how to use it in a HTML document

Similar presentations


Presentation on theme: "JavaScript Syntax, how to use it in a HTML document"— Presentation transcript:

1 JavaScript Syntax, how to use it in a HTML document
Lecture 8: JavaScript JavaScript Syntax, how to use it in a HTML document

2 What is JavaScript JavaScript is a programming language that can be executed in almost every modern browser. It is different from traditional programming language such as C++, Java. It is a interpreted or scripting language. Do not need to be compiled before execution. Must be executed by an interpreter. A browser contains a JavaScript interpreter.

3 What is JavaScript JavaScript is client-side programming language.
It is executed in the browser of a client, not on a web server. It allows interaction on client side. For example, an image can be changed to another when a user moves his mouse over the image.

4 How to use JavaScript JavaScript code can be inserted into a HTML file. In both <head> and <body> For example <head> <title>JS Hello World</title> <script type="text/javascript"> window.alert("Hello World"); </script> </head>

5 How to use JavaScript You can insert JavaScript in <body> as well For example <body> <script type="text/javascript"> window.alert("Hello World"); </script> </body>

6 How to use JavaScript JavaScript code in HTML must be inside the <script> tag. JavaScript can be also included from external sources using <script> tag. Just put the following into <head> tag <script type="text/javascript” src=“filename.js>

7 How to use JavaScript JavaScript code in HTML must be inside the <script> tag. JavaScript can be also included from external sources using <script> tag. Just put the following into <head> tag <script type="text/javascript” src=“filename.js>

8 JavaScript Syntax Every JavaScript statement must end with a semicolon ; If it is inside a HTML file, JavaScript must be inside the <script> tag For example, <script> var number = 10; //declare a variable named number

9 JavaScript Syntax JavaScript’s basic syntax is identical to that of C++ and Java. // begins a comment that ends at the end of the line /* and */ may be used to contain multiline comments For instance //This is number 1 /*I assigned 10 to the variable number.*/

10 JavaScript Syntax Variables names are case sensitive.
JavaScript does not have typed variables. The variable declarations do not specify a data type for the variables When you declare a variable, always start with keyword var var num1 = 10; var Num1 = 20; //this is ok because of case sensitivity var color = ‘c’; var firstname = “David”

11 JavaScript Syntax Similarities between JavaScript and C++.
Most of operators are the same as in Java and C++ !=, +, &, /, %, >, < JavaScript uses braces to enclose statement blocks and its syntax for assignment (=) and control statements (if, while) are the same as in Java and C++.

12 Next class Variables and Data Types Statements Operators Expression
Block statement Keyword statement Operators +, -, *, /, %, ==, ++, --, <, >, etc


Download ppt "JavaScript Syntax, how to use it in a HTML document"

Similar presentations


Ads by Google