SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Javascript




    Introduction

      by Amit Tyagi
What Is JavaScript?

   Executes in Host Environment ( mostly
    Browser).
   Interpreted language.
   Major use cases are:
    a.          making web pages dynamic (animations,
         RICH UI)
    b.         form validation
    c.         background communication with server
         (AJAX) etc.
    d.   ….
History

   Initially LiveScript from Netscape.
   JScript from Microsoft.
   ECMA introduced ECMAScript for
    standardized Scripting language.
   Current Version is 5.1 of ECMA-262.
The Core (ECMAScript)

    ECMA-262 describes it like this:
    “ECMAScript can provide core scripting capabilities
    for a variety of host environments, and therefore the
    core scripting language is specified...apart from any
    particular host environment.”
                         ECMAScript
                                |
                ----------------------------------------
                |                 |                   |
            JavaScript              Actionscript        ScriptEase
The Document Object Model (DOM)

   The Document Object Model (DOM) is an
    application programming interface (API) for
    HTML as well as XML.
DOM

<html>
   <head>
          <title>Sample Page</
   title>
   </head>
   <body>
          <p>Hello World!</p>
   </body>
</html>
The Browser Object Model (BOM)

   BOM deals with the browser window and
    frames.
   All function and properties starting inside
    window object.
   Internet Explorer extends the BOM to include
    the ActiveXObject class, which can be used
    to instantiate ActiveX objects through
    JavaScript.
Browser Object Model (BOM)
DOM and JS World
How to include JS in a web page

Inside <script> tags
       <script>
              var a = 10;
              alert(a);
       </script>
Within external file
       <script src=“page.js“
type=“text/javascript” ></script>
Javascript Basics
Syntax

   Mostly like C and java.
   Everything is case-sensitive.
   Variables are loosely typed.
   End-of-line semicolons are optional.
   Comments are the same as in Java, C, and
    Perl.
Variables

   var test = "hi“, test2, $number;
   Variable declaration is optional.
Keywords

break      else         new      var
case       finally      return   void
catch      for          switch   while
continue   function     this     with
default    if           throw
delete     in           try
do         instanceof   typeof
Reserved Words

abstract   enum         int         short
boolean    export       interface   static
byte       extends      long        super
char       final        native      synchronized
class      float        package     throws
const      goto         private     transient
debugger   implements   protected   volatile
double     import       public
Statements

   The if statement
     –    if (condition) statement1 else statement2
   do-while
     –    do { statements } while (condition )
   While
     –    while (condition) { statements}
   for
     –    for (initialization; condition; post-loop-expression)
           { statements}
   for-in
           for (property in expression) {statements}
Data types

   Primitive values

   Reference values
Primitive values

   undefined
   null
   boolean
   number
   string

Use typeof keyword to check type of variable.
Reference Types

   Classes or Object
   The Object class – similar to java.lang.Object
        var car = new Object();

Or
        var myClass = function(){};
        var myObject = new myClass();

Or JSON way
     var myObject = {};
Memory Allocation
Classes and objects in
javascript

   No class keyword available, instead
    constructor function works as class definition.
   Classes and objects are dynamic, can be
    altered at runtime.
Builtin Objects


Object        Function    Array        String
Boolean       Number      Date         RegExp
Error         EvalError   RangeError   ReferenceError
SyntaxError   TypeError   URIError
Function defination

     function showInfo(a) {
          alert(a);
     }

     var showInfo = function(a)
{ alert(a);}

     var showInfo = new Function(“a”,
“alert(a)”);
Functions ( contd.)

   Functions are also object, in fact everything
    is an object in JavaScript
   Functions can return any data type,
    ‘undefined’ if none specified.
Functions scope

By default in window scope
this points to current object’s scope, defaults
to window

Can be altered using call and apply method
     func.call(any_scope, [arg1,
arg2, ..]);
     func.apply(any_scope, arg1,
arg2,..);
Using function as Class

var Policy = function(name) {
                  this.policyName = name;
            }
var pol1 = new Policy(“AccessPolicy”);
var pol2 = new Policy(“AuthenticationPolicy”);

console.log(pol1.policyName); // AccessPolicy
console.log(pol2.policyName); //
AuthenticationPolicy
Variables scope

1.   Start from local scope and ends till global
     scope.
function closures
Prototype property

Every function has a prototype property
Every object’s scope chain fall backs to constructor
function’s prototype.
var func = function() {this.a=10; }
func.prototype.a = 20;
var obj = new func();
console.log(obj.a); // 10
delete obj.a;
console.log(obj.a); // 20
Prototype
Prototype facts

   Prototype object is common across all
    instances of the function( class)
   Prototype is dynamic, any changes made in
    prototype gets reflected in all object
    instances instantly.
__proto__ and constructor

var func = function() { }
func.prototype.a = 10;
var obj = new func();
obj.a; // 10
obj.__proto__.a ; // 10
obj.constructor.prototype.a; // a
Using prototype to create class

var funcA = function() {this.a = 10;}
funcA.prototype.b = 20;
funcA.prototype.doSomething = function()
{ }

var objA = new funcA();
funcA.prototype.c = 30;
console.log(objA);
Prototype chaining

var A = function(){};

var B = function(){};
B.prototype = new A();
B.prototype.constructor
= B;

var X = new B();
JSON

JavaScript Object Notation
Array []
Object {“key”:”value, ….}

var obj = {};
obj.a = 10;
obj.doSomething = function(){};
Using JSON to create object and
class

var myClass = function (arg1) {
            var _property1 = 20;
            var _method = function() {};
            return {
                  public_property:arg1,
                  public_method:function() {
                        _method();
                        }
                  };
}
var myObject = new myClass(10);
AJAX

Asynchronous JavaScript And ( Advanced)
XML
XMLHttpRequest Object
AJAX Request
XMLHttpRequest – cross browser Support

if (typeof XMLHttpRequest == "undefined") {

 XMLHttpRequest = function () {
  try { return new
   ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch
(e) {}
  try { return new
   ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch
(e) {}
  try { return new
   ActiveXObject("Microsoft.XMLHTTP"); } catch
(e) {}
  throw new Error("This browser does not support
Ajax example

var xhr = new XMLHttpRequest();
xhr.onreadystatechange =
 function() {
  if(xhr.readyState == 4){
alert(xhr. responseText);
  }
 };
xhr.open("GET","page.xml",true);
xhr.send(null);
Event Handling

Event propagation and event Bubbling

                        IE only support event
                        bubbling
Adding event Handlers

Mozilla compatible browsers
[elementObject].addEventListener(“event_h
andler”, handlerFunction, boolCapture);
[elementObject].removeEventListener(“even
t_handler”, handlerFunction,
boolCapture);
IE
[elementObject].attachEvent(“event_handle
r”, handlerFunction);
[elementObject].detachEvent(“event_handle
r”, handlerFunction);
Timing functions

setTimeout– calls only once
var timeoutVar =
setTimeout( function_to_call,
milliseconds);
clearTimeout(timeoutVar);

setInterval – calls repeatedly
var intervalVar =
setInterval( function_to_call,
milliseconds);
clearInterval(intervalVar);
DOM API

document.getElementById
document.getElementsByTagName

document.createElement
document.appendChild

elementObject.innerHTML
Introduction to Javascript
Introduction to Javascript

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScriptT11 Sessions
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...Edureka!
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 

Was ist angesagt? (20)

Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Js ppt
Js pptJs ppt
Js ppt
 
Javascript
JavascriptJavascript
Javascript
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Javascript
JavascriptJavascript
Javascript
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 

Andere mochten auch

Andere mochten auch (8)

Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 

Ähnlich wie Introduction to Javascript

jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsPrasad Shende
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application FrameworkJady Yang
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript MisunderstoodBhavya Siddappa
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascriptRobbin Zhao
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript BasicsMindfire Solutions
 
Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Sopheak Sem
 

Ähnlich wie Introduction to Javascript (20)

oojs
oojsoojs
oojs
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation Labs
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02
 

Kürzlich hochgeladen

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

Introduction to Javascript

  • 1. Javascript Introduction by Amit Tyagi
  • 2. What Is JavaScript?  Executes in Host Environment ( mostly Browser).  Interpreted language.  Major use cases are: a. making web pages dynamic (animations, RICH UI) b. form validation c. background communication with server (AJAX) etc. d. ….
  • 3. History  Initially LiveScript from Netscape.  JScript from Microsoft.  ECMA introduced ECMAScript for standardized Scripting language.  Current Version is 5.1 of ECMA-262.
  • 4. The Core (ECMAScript)  ECMA-262 describes it like this: “ECMAScript can provide core scripting capabilities for a variety of host environments, and therefore the core scripting language is specified...apart from any particular host environment.” ECMAScript | ---------------------------------------- | | | JavaScript Actionscript ScriptEase
  • 5. The Document Object Model (DOM)  The Document Object Model (DOM) is an application programming interface (API) for HTML as well as XML.
  • 6. DOM <html> <head> <title>Sample Page</ title> </head> <body> <p>Hello World!</p> </body> </html>
  • 7. The Browser Object Model (BOM)  BOM deals with the browser window and frames.  All function and properties starting inside window object.  Internet Explorer extends the BOM to include the ActiveXObject class, which can be used to instantiate ActiveX objects through JavaScript.
  • 9. DOM and JS World
  • 10. How to include JS in a web page Inside <script> tags <script> var a = 10; alert(a); </script> Within external file <script src=“page.js“ type=“text/javascript” ></script>
  • 12. Syntax  Mostly like C and java.  Everything is case-sensitive.  Variables are loosely typed.  End-of-line semicolons are optional.  Comments are the same as in Java, C, and Perl.
  • 13. Variables  var test = "hi“, test2, $number;  Variable declaration is optional.
  • 14. Keywords break else new var case finally return void catch for switch while continue function this with default if throw delete in try do instanceof typeof
  • 15. Reserved Words abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public
  • 16. Statements  The if statement – if (condition) statement1 else statement2  do-while – do { statements } while (condition )  While – while (condition) { statements}  for – for (initialization; condition; post-loop-expression) { statements}  for-in for (property in expression) {statements}
  • 17. Data types  Primitive values  Reference values
  • 18. Primitive values  undefined  null  boolean  number  string Use typeof keyword to check type of variable.
  • 19. Reference Types  Classes or Object  The Object class – similar to java.lang.Object var car = new Object(); Or var myClass = function(){}; var myObject = new myClass(); Or JSON way var myObject = {};
  • 21. Classes and objects in javascript  No class keyword available, instead constructor function works as class definition.  Classes and objects are dynamic, can be altered at runtime.
  • 22. Builtin Objects Object Function Array String Boolean Number Date RegExp Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
  • 23. Function defination function showInfo(a) { alert(a); } var showInfo = function(a) { alert(a);} var showInfo = new Function(“a”, “alert(a)”);
  • 24. Functions ( contd.)  Functions are also object, in fact everything is an object in JavaScript  Functions can return any data type, ‘undefined’ if none specified.
  • 25. Functions scope By default in window scope this points to current object’s scope, defaults to window Can be altered using call and apply method func.call(any_scope, [arg1, arg2, ..]); func.apply(any_scope, arg1, arg2,..);
  • 26. Using function as Class var Policy = function(name) { this.policyName = name; } var pol1 = new Policy(“AccessPolicy”); var pol2 = new Policy(“AuthenticationPolicy”); console.log(pol1.policyName); // AccessPolicy console.log(pol2.policyName); // AuthenticationPolicy
  • 27. Variables scope 1. Start from local scope and ends till global scope.
  • 29. Prototype property Every function has a prototype property Every object’s scope chain fall backs to constructor function’s prototype. var func = function() {this.a=10; } func.prototype.a = 20; var obj = new func(); console.log(obj.a); // 10 delete obj.a; console.log(obj.a); // 20
  • 31. Prototype facts  Prototype object is common across all instances of the function( class)  Prototype is dynamic, any changes made in prototype gets reflected in all object instances instantly.
  • 32. __proto__ and constructor var func = function() { } func.prototype.a = 10; var obj = new func(); obj.a; // 10 obj.__proto__.a ; // 10 obj.constructor.prototype.a; // a
  • 33. Using prototype to create class var funcA = function() {this.a = 10;} funcA.prototype.b = 20; funcA.prototype.doSomething = function() { } var objA = new funcA(); funcA.prototype.c = 30; console.log(objA);
  • 34. Prototype chaining var A = function(){}; var B = function(){}; B.prototype = new A(); B.prototype.constructor = B; var X = new B();
  • 35. JSON JavaScript Object Notation Array [] Object {“key”:”value, ….} var obj = {}; obj.a = 10; obj.doSomething = function(){};
  • 36. Using JSON to create object and class var myClass = function (arg1) { var _property1 = 20; var _method = function() {}; return { public_property:arg1, public_method:function() { _method(); } }; } var myObject = new myClass(10);
  • 37. AJAX Asynchronous JavaScript And ( Advanced) XML XMLHttpRequest Object
  • 39. XMLHttpRequest – cross browser Support if (typeof XMLHttpRequest == "undefined") { XMLHttpRequest = function () { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {} try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} throw new Error("This browser does not support
  • 40. Ajax example var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if(xhr.readyState == 4){ alert(xhr. responseText); } }; xhr.open("GET","page.xml",true); xhr.send(null);
  • 41. Event Handling Event propagation and event Bubbling IE only support event bubbling
  • 42. Adding event Handlers Mozilla compatible browsers [elementObject].addEventListener(“event_h andler”, handlerFunction, boolCapture); [elementObject].removeEventListener(“even t_handler”, handlerFunction, boolCapture); IE [elementObject].attachEvent(“event_handle r”, handlerFunction); [elementObject].detachEvent(“event_handle r”, handlerFunction);
  • 43. Timing functions setTimeout– calls only once var timeoutVar = setTimeout( function_to_call, milliseconds); clearTimeout(timeoutVar); setInterval – calls repeatedly var intervalVar = setInterval( function_to_call, milliseconds); clearInterval(intervalVar);