Javascript

700 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
700
On SlideShare
0
From Embeds
0
Number of Embeds
109
Actions
Shares
0
Downloads
64
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Javascript

  1. 1. JAVASCRIPT Week 9, Day 1
  2. 2. Introduction to Scripting • Scripting Languages are mainly used to build the programming environment in HTML document .It Makes Web pages dynamic and interactive. • There are 2 types of scripting languages • Client side scripting languages • Are scripts that execute on client side or the browser. Browser Includes Scripting Interpreter • Eg: VBScript, JavaScript, Jscript and ECMA Script • Server side scripting languages • Are scripts that execute on server side • Eg: PHP,JSP, ASP .NET
  3. 3. Features of JavaScript  C-based language developed by Netscape  Mainly used for client side scripting because it is supported by all the browsers.  Platform Independence  JavaScript is NOT supported by old browsers (IE 1.0). You can enable or disable JS in new browsers
  4. 4. How to start programming in JavaScript • All JavaScript Code must be in between the below tags <script> // JavaScript Code goes here </script>
  5. 5. How to start programming in JavaScript • JavaScript can be embedded to any HTML code in two ways –Immediate scripting –Deferred Scripting
  6. 6. Immediate Mode Scripting • SCRIPT tag can be placed in HEAD or BODY tag • Placing JavaScript in the HEAD tag ensures readability. • Scripts gets executed as the page loads. <body> <h4> Immediate Demo</h4> <script language="JavaScript"> document.write("<h5> Using JavaScript</h5>"); </script> </body>
  7. 7. <script language="JavaScript"> /*calling function when user clicks on the button */ function msg(){ alert("Hi"); } </script> <form name="f1"> <input type="button" value=" ok " onClick="msg()"> </form> Deferred Mode Scripting –Script is executed based on some user action
  8. 8. JavaScript – lexical structure • JavaScript is object based and action-oriented. • JavaScript is case sensitive. • A semicolon ends a JavaScript statement
  9. 9. Commenting C // comment single line /* comment multiple lines */ JavaScript //comment single line /* Comment multiple Lines*/
  10. 10. Declaring a variable C //Declaring a variable Int a=10; Char c=‘a’; Float f=1.12; JavaScript //No need of prior Declarations Var a=10; //local b=15; //global
  11. 11. Variables in Detail • Must start with a letter or an underscore and can have digits. • The Data type is automatically decided by the usage. • Scope is by default global. If a variable is prefixed by the keyword ‚var‛ within a function then it is a local variable. • The formal parameters are local to the function. function demo() { var inum1 = 10; // Local to the function inum2 = 20; // Global to the document. } demo(); // Invoking function inum1 = inum1+1; // Error because inum1 is local variable inum2 = inum2+1; // no Error
  12. 12. JavaScript – Implicit data types • JavaScript recognizes the following implicit data types – Number – String – Logical – Object – The special value null • Type conversion – JavaScript automatically converts between data types str = ‚100‛, num1 = 10, num2 = 20 num3 = num1+ num2 strsum = str + num2 strsum = num2 + str 30 10020 20100
  13. 13. Output C Int a=10,b=25; Printf(‚%d %d‛,a,b); JavaScript Var a=10; var b=25; Document.write(a,b);
  14. 14. Control Structures C Conditional Control Structures • If • If else • Switch Loops • For • While • Do while JavaScript ‚Exactly the same as on left side‛
  15. 15. Functions C Int findSum(int a,int b) { Int c; c=a+b; Return c } findSum(10,15); JavaScript function findSum(a,b) { c=a+b; Return c; } findSum(10,15);
  16. 16. Operators C Arithmetic Operators +, ++, -, --, *, /, % Relational Operators ==, !=, ===, !==, >, >=, < , <= Logical Operators &&, ||, ! Assignment Operators =, +=, -=, *=, /=, %= Strict equal (===) Strict not equal (!==) Returns true if the operands are not equal and/or not of the same type. JavaScript ‚Exactly the same as on left side‛
  17. 17. Dialog boxes (Window Object methods) • Alert dialog box - alert(message) – Takes in a string argument and displays an alert box. • Prompt dialog box - prompt(message,[inputDefault]) – Displays a message and a data entry field • Confirm dialog box - confirm(message ) – Serves as a technique for confirming user actions
  18. 18. Questions? ‚A good question deserve a good grade…‛
  19. 19. End of Day
  20. 20. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com

×