1 / 12

Lecture 8: JavaScript

Lecture 8: JavaScript. JavaScript Syntax, how to use it in a HTML document. 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.

Download Presentation

Lecture 8: JavaScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 <script>

  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’; varfirstname = “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 • Expression • Block statement • Keyword statement • Operators • +, -, *, /, %, ==, ++, --, <, >, etc

More Related