SlideShare a Scribd company logo
JAVASCRIPT

Aditya Gaur   Mentor: Apurba Nath
Do we really need to learn
Javascript?
YES!! But why?
   Language of web browser.
   Its not “some other language”.
   The most misunderstood language
Javascript
   developed by Brendan Eich of Netscape
    under the name Mocha
   Renamed to livescript.
   Finally to javascript
   Sometimes also called ECMAscript
   first appeared in that Navigator 2.0 browser
Prototypal Language
   Javascript is classless object oriented
    language.
     Whaaaat?
     How can we think of OOPS without class?
Classical vs Prototypal

                 Java       Javascript

     Classical          Prototypal

     Classes            Functions

     Constructors       Functions

     Methods            Functions
Object creation

   Using Object literal

   var newObject ={
   first: 10,
   second: "aValue"
   };
   alert(newObject.first)
   Using constructor function

   var newClass = function(){
   this.first= 10;
   this.second="aValue";
   };
   var newObject = new newClass();
   alert(newObject.first);
What's the difference?

   The constructor maintain a link back to the
    function that constructed them.
   This is important when we are using the prototype
    feature.
           var newClass = function(){
                  this.first= 10;
                  this.second="aValue";
           };
           var newObject = new newClass();
           alert(newObject.constructor);
Why do we need classes?

   Code reuse
   Making user defined types
Javascript object prototype

   It is javascript’s way of sharing implementation
    across similar objects
   No Classes
   All objects are created by adding properties and
    methods to an empty object or by cloning an
    existing one.
   Prototype-based inheritance - an existing
    object is used as a template to build other objects
How does it work?

   Prototypes are implemented in javascript using
    the prototype property of constructor functions.
   The prototype property is basically a template for
    the objects created by the constructor.
How does it work?

var newClass = function(){
this.first= 10;
this.second="aValue";
};

newClass.prototype.one = 1;
var newObject = new newClass();
newObject.constructor.prototype.two = 2;
alert(newObject.constructor.prototype.one); //1
alert(newObject.constructor.prototype.two); //2

var anotherObject = new newClass();
alert(anotherObject.constructor.prototype.two); //2
How does it work?
function Pet(name, species, hello)
{
  this.name = name;
  this.species = species;
  this.hello = hello;
}

Pet.prototype.sayHello = function()
{
   alert(this.hello);
}

var rufus = new Pet("Rufus", "cat", "miaow");
rufus.sayHello();
Inheritance

   Inheritence is achieved via Prototype Chaining
   How to define a prototype object?
     Just define the prototype of the derived object
      to be equal to the prototype object
Inheritance
function Pet()                         OUTPUT: Default Name
{                                              meow
  this.name = "Default Name";
   this.sound = "Default Sound";
}
Pet.prototype.makeSound= function(){
   alert(this.sound);
}
Pet.prototype.getName = function(){
   alert(this.name);
}
var aPet = new Pet();
function Cat(){
   this.sound = "meow";
}
Cat.prototype = aPet;
var aCat = new Cat();
aCat.getName();
aCat.makeSound();
Prototype Chaining
Object.prototype.inObj = 1;
function A()
{
   this.inA = 2;
}
A.prototype.inAProto = 3;
function B()
{
   this.inB = 4;
}
B.prototype = new A;
B.prototype.constructor = B;
B.prototype.inBProto = 5;
 x = new B;
document.write(x.inObj + ', ' + x.inA + ', ' + x.inAProto + ', ' + x.inB
+ ', ' + x.inBProto);
The “new”
   We need the keyword “new” to carry out
    inheritence
   But it has a drawback:

    var func = function(){         OUTPUT : Window.object
      alert(this);                          object.object
    }
    var aVar = func();
    var anotherVar = new func();



       Also it gives us an impression of Class based
        language
The “new”
   S o we can do the following:
    Method 1                       Method 2
    function func(){               function func(){
       this.name = "foo";             if (!(this instanceof func) )
    }                                   return new func();
    function newObject(obj){           this.name = "foo";
       return new obj();           }
    }                              var anObj = func();
    var anObj = newObject(func);   alert(anObj.name);
    alert(anObj.name);
Back up slides
Dynamically Typed
   Type: metadata about a chunk of memory
    that classifies the kind of data stored there.
   Type declaration is not necessary.
        var aVar = 10; //type: Number
        var anotherVar = true; // type: Boolean


   Variables in JavaScript are typed, but that type
    is determined internally. In the example, var
    aVar will be type Number and var
    anotherVar will be type Boolean. 
Weekly Typed
   Variables are not of a specific data type.
            var aVar = 10; // Number
            aVar = true; // Boolean
            aVar = “This is a string!” // String
Closures
   a closure is the local variables for a function -
    kept alive after the function has returned, or
   a closure is a stack-frame which is not
    deallocated when the function returns.
Non C losure (E xample)
                            void sayNumber(){
                                int num = 10;
                                printf(“%d”,num);
                                return;
                            }
                            sayNumber();

When the function “sayNumber” is called, it creates a stack frame for itself and the
variable “num” will exist in the stack.
As soon as the function returns the variable “num” ceases to exist.
C losure (E xample)
  function sayName(name) {                               Ouput: I am foo
      var phrase = "I am" + name;
      var sayString = function() {
          alert(phrase);
      };
      return sayString;
  }
  var say = sayName(“foo");
  say();


In this case too the stack frames are created but here the inner functions have
access to the outer function’s variable even after the outer function has returned.
C losure (More E xample)
    function sayName(name) {                            Ouput: My name is foo
        var phrase = "I am" + name;
        var sayString = function() {
            alert(phrase);
        };
        phrase = "My name is" + name;
        return sayString;
    }
    var say = sayName(“foo");
    say();  

This example shows that the variables are not copied. Their reference is stored.
Ad

More Related Content

What's hot (20)

Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
Sasidhar Kothuru
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Javascript - Tutorial
Javascript - TutorialJavascript - Tutorial
Javascript - Tutorial
adelaticleanu
 
Javascript
JavascriptJavascript
Javascript
Manav Prasad
 
Java script
Java scriptJava script
Java script
Rajkiran Mummadi
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
Java script
Java scriptJava script
Java script
Soham Sengupta
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
Javascript
JavascriptJavascript
Javascript
guest03a6e6
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Java script basics
Java script basicsJava script basics
Java script basics
Shrivardhan Limbkar
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
Collaboration Technologies
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
Doug Jones
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Javascript - Tutorial
Javascript - TutorialJavascript - Tutorial
Javascript - Tutorial
adelaticleanu
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
Doug Jones
 

Viewers also liked (7)

03 HTML/CSS/JA Conceptos mínimos
03 HTML/CSS/JA Conceptos mínimos03 HTML/CSS/JA Conceptos mínimos
03 HTML/CSS/JA Conceptos mínimos
Víctor Manuel García Luna
 
Java script
 Java script Java script
Java script
bosybosy
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
msemenistyi
 
Curso FPE Diseño Web. Módulo 2. El HTML
Curso FPE Diseño Web. Módulo 2. El HTMLCurso FPE Diseño Web. Módulo 2. El HTML
Curso FPE Diseño Web. Módulo 2. El HTML
Diseñática disenatica.com
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
Vijay Kumar Verma
 
HTML/CSS/java Script/Jquery
HTML/CSS/java Script/JqueryHTML/CSS/java Script/Jquery
HTML/CSS/java Script/Jquery
FAKHRUN NISHA
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Ad

Similar to Javascript (20)

Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
Massimo Franciosa
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
Let's JavaScript
Let's JavaScriptLet's JavaScript
Let's JavaScript
Paweł Dorofiejczyk
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
Ratnala Charan kumar
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
LearningTech
 
The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming Primer
Mike Wilcox
 
JavaScript Execution Context
JavaScript Execution ContextJavaScript Execution Context
JavaScript Execution Context
Juan Medina
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
David Atchley
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
Doeun KOCH
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
Mindfire Solutions
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
Rodica Dada
 
Prototype
PrototypePrototype
Prototype
Aditya Gaur
 
4front en
4front en4front en
4front en
Vitaly Hornik
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
Jin-Hwa Kim
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
Joe Zulli
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Donald Sipe
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
MD Sayem Ahmed
 
The many facets of code reuse in JavaScript
The many facets of code reuse in JavaScriptThe many facets of code reuse in JavaScript
The many facets of code reuse in JavaScript
Leonardo Borges
 
oojs
oojsoojs
oojs
Imran shaikh
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
Chris Saylor
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
Massimo Franciosa
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
Ratnala Charan kumar
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
LearningTech
 
The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming Primer
Mike Wilcox
 
JavaScript Execution Context
JavaScript Execution ContextJavaScript Execution Context
JavaScript Execution Context
Juan Medina
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
Doeun KOCH
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
Mindfire Solutions
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
Jin-Hwa Kim
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
Joe Zulli
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Donald Sipe
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
MD Sayem Ahmed
 
The many facets of code reuse in JavaScript
The many facets of code reuse in JavaScriptThe many facets of code reuse in JavaScript
The many facets of code reuse in JavaScript
Leonardo Borges
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
Chris Saylor
 
Ad

Recently uploaded (20)

UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 

Javascript

  • 1. JAVASCRIPT Aditya Gaur Mentor: Apurba Nath
  • 2. Do we really need to learn Javascript?
  • 3. YES!! But why?  Language of web browser.  Its not “some other language”.  The most misunderstood language
  • 4. Javascript  developed by Brendan Eich of Netscape under the name Mocha  Renamed to livescript.  Finally to javascript  Sometimes also called ECMAscript  first appeared in that Navigator 2.0 browser
  • 5. Prototypal Language  Javascript is classless object oriented language.  Whaaaat?  How can we think of OOPS without class?
  • 6. Classical vs Prototypal Java Javascript Classical Prototypal Classes Functions Constructors Functions Methods Functions
  • 7. Object creation Using Object literal var newObject ={ first: 10, second: "aValue" }; alert(newObject.first) Using constructor function var newClass = function(){ this.first= 10; this.second="aValue"; }; var newObject = new newClass(); alert(newObject.first);
  • 8. What's the difference?  The constructor maintain a link back to the function that constructed them.  This is important when we are using the prototype feature. var newClass = function(){ this.first= 10; this.second="aValue"; }; var newObject = new newClass(); alert(newObject.constructor);
  • 9. Why do we need classes?  Code reuse  Making user defined types
  • 10. Javascript object prototype  It is javascript’s way of sharing implementation across similar objects  No Classes  All objects are created by adding properties and methods to an empty object or by cloning an existing one.  Prototype-based inheritance - an existing object is used as a template to build other objects
  • 11. How does it work?  Prototypes are implemented in javascript using the prototype property of constructor functions.  The prototype property is basically a template for the objects created by the constructor.
  • 12. How does it work? var newClass = function(){ this.first= 10; this.second="aValue"; }; newClass.prototype.one = 1; var newObject = new newClass(); newObject.constructor.prototype.two = 2; alert(newObject.constructor.prototype.one); //1 alert(newObject.constructor.prototype.two); //2 var anotherObject = new newClass(); alert(anotherObject.constructor.prototype.two); //2
  • 13. How does it work? function Pet(name, species, hello) { this.name = name; this.species = species; this.hello = hello; } Pet.prototype.sayHello = function() { alert(this.hello); } var rufus = new Pet("Rufus", "cat", "miaow"); rufus.sayHello();
  • 14. Inheritance  Inheritence is achieved via Prototype Chaining  How to define a prototype object?  Just define the prototype of the derived object to be equal to the prototype object
  • 15. Inheritance function Pet() OUTPUT: Default Name { meow this.name = "Default Name"; this.sound = "Default Sound"; } Pet.prototype.makeSound= function(){ alert(this.sound); } Pet.prototype.getName = function(){ alert(this.name); } var aPet = new Pet(); function Cat(){ this.sound = "meow"; } Cat.prototype = aPet; var aCat = new Cat(); aCat.getName(); aCat.makeSound();
  • 16. Prototype Chaining Object.prototype.inObj = 1; function A() { this.inA = 2; } A.prototype.inAProto = 3; function B() { this.inB = 4; } B.prototype = new A; B.prototype.constructor = B; B.prototype.inBProto = 5; x = new B; document.write(x.inObj + ', ' + x.inA + ', ' + x.inAProto + ', ' + x.inB + ', ' + x.inBProto);
  • 17. The “new”  We need the keyword “new” to carry out inheritence  But it has a drawback: var func = function(){ OUTPUT : Window.object alert(this); object.object } var aVar = func(); var anotherVar = new func();  Also it gives us an impression of Class based language
  • 18. The “new”  S o we can do the following: Method 1 Method 2 function func(){ function func(){ this.name = "foo"; if (!(this instanceof func) ) } return new func(); function newObject(obj){ this.name = "foo"; return new obj(); } } var anObj = func(); var anObj = newObject(func); alert(anObj.name); alert(anObj.name);
  • 20. Dynamically Typed  Type: metadata about a chunk of memory that classifies the kind of data stored there.  Type declaration is not necessary. var aVar = 10; //type: Number var anotherVar = true; // type: Boolean  Variables in JavaScript are typed, but that type is determined internally. In the example, var aVar will be type Number and var anotherVar will be type Boolean. 
  • 21. Weekly Typed  Variables are not of a specific data type. var aVar = 10; // Number aVar = true; // Boolean aVar = “This is a string!” // String
  • 22. Closures  a closure is the local variables for a function - kept alive after the function has returned, or  a closure is a stack-frame which is not deallocated when the function returns.
  • 23. Non C losure (E xample) void sayNumber(){ int num = 10; printf(“%d”,num); return; } sayNumber(); When the function “sayNumber” is called, it creates a stack frame for itself and the variable “num” will exist in the stack. As soon as the function returns the variable “num” ceases to exist.
  • 24. C losure (E xample) function sayName(name) { Ouput: I am foo     var phrase = "I am" + name;     var sayString = function() {         alert(phrase);     };     return sayString; } var say = sayName(“foo"); say(); In this case too the stack frames are created but here the inner functions have access to the outer function’s variable even after the outer function has returned.
  • 25. C losure (More E xample)   function sayName(name) { Ouput: My name is foo       var phrase = "I am" + name;       var sayString = function() {           alert(phrase);       };       phrase = "My name is" + name;       return sayString;   }   var say = sayName(“foo");   say();   This example shows that the variables are not copied. Their reference is stored.