SlideShare uma empresa Scribd logo
1 de 5
Baixar para ler offline
Articles from Jinal Desai .NET
Exam 70-480 Javascript
2013-01-20 14:01:22 Jinal Desai

The article is intended for Microsoft Certification Exam 70-480 aspirants. All the
points covered in this article is described from exam 70-480 point of view only.
Some advanced topics like Promises, Web Worker, Web Sockets will be covered in
my next article.

Variable Types
string, number, boolean, array, objects, null, undefined

Functions
Callable Behaviors
Implemented as Objects
Hoisting: Call functions before they are defined is called hoisting.
f1();
function f1() {
alert(“f1”);
}

Function Arguments
Internally Passed: Contains all the arguments in “arguments” array variable.

Function Scope
e.g.
var ops={
add:function addNumbers(n1, n2) {
}
}
var x = ops.add(5,8); //valid
var y = ops.addNumbers(5, 8); //Invalid
//Function addNumbers can be called internally but not from outside
e.g.
function outer(n) {
function inner() {
return n*n;
}
return inner();
}

Immediate Functions
Immediate functions called automatically, no need to call it explicitly.
(function(){ }());
or
(function(){})();
Function as argument
function add(n1, n2) {
return n1+n2;
}
function calc(proc, n1, n2) {
return proc(n1, n2);
}
calc(add, 5, 8);

Arrays
Array functions:
push, pop, concat, map, filter, some, every, forEach, reduce, sort, splice, join,
reverse
var x=[];
var y=[6];
var fruit=[“apple”,”banana”];
fruit.push(“orange”);
var orange = fruit.pop();
var otherFruit = [“banana”];
fruit = fruit.concat(otherFruit);
var apple = fruit.splice(0,1); //0 to 1 items, 0 based array
var malon = fruit.splice(3,1,”malon”,”grapes”); //it will splice 4th item

Array Projections
fruit=fruit.map(function(i) {
return i.toUpperCase();
});

fruit=fruit.map(function(i){
return{ FruitName: i.toUpperCase();
});

fruit=fruit.filter(function(i){
return i[0]===’a';
});

bool result = fruit.every(function(i){
return i[0]===’a';
}); //returns true if every fruit name starts with ‘a’

bool result = fruit.every(function(i){
return i.length>0
}); //returns true if all the fruit name length is greater than 0.

bool result = fruit.some(function(i){
return i[0]===’a';
}); //returns true if some of the fruits starts with ‘a’.

var length=[];
fruit.forEach(function(i){
length[counter++]=i.length;
});

Objects in Javascript
var obj = { };
obj.FirstName=”Jinal”;
obj.SayHello=function(){ alert(“Hello”); };
or
var obj = {
FirstName = “Jinal”,
SayHello=function(){ alert(“Hello”); }
};

DOM Interactions
Quering the DOM
var x = document.getElementById(“anyId”);
or
var x = document.getElementById(“#anyId”);

var y = document.getElementByTagName(“h1”);
var z = document.querySelector(“.item”);
var collection = document.querySelectorAll(“.className”);

Manipulating DOM
var x = document.querySelector(“#anyId”);
x.innerText = “changed inner text”;
x.className = “NewClassName”;
x.classList.add(“item”);

Responding to events
Declarative
<button id=”button” onclick=”handler();”>Click Here</button>
//Javascript
function handler(){
}

Programmatic
var b=document.querySelector(“#button”);
b.addEventListener(“click”,handler);
or
b.onclick=handler;
or
//anonymous function
b.onclick=function(){
}

Remove event listener programmatically
b.removeEventListener(“click”, handler);
It is not possible to remove event once it is bind using declarative method.

Advanced Topics
Handling Exceptions
Two ways: Managing failure in code or minimizing failure in code.
How to manage failure in code?
Try{
}
catch(e){
}
finally{
}

function throwHelper(){
var error = new Error(123, “error”);
throw error;
}

try{
throwHelper();
}
catch(error){
var msg=error.number + “ : “ + error.message;
}

Another way to throw error in windows is
throw new WinJS.ErrorFromName(“args”,”error”);

Promises
Asynchronous Call
WinJS.xhr((url=”url”, headers={Accept:”application/json”}).then(
function(xhr){
var result = JSON.parse(xhr.response);});

Web Worker
WinJS.UI.Pages.define(“/pages/webworker/webworker.html”,
{ready:function(element,options){
var worker=new worker(“/pages/webworker/task.js”);
worker.onmessage=function(e){
logMessage(“The worker process said “ + e.message);
};
worker.postMessage(“Hey there, how are you?”);
}
};
//task.js
self.onMessage=function(e){
self.postMessage(“I am away “ + e.data);
};
Web Socket
It allows to talk to lower level http.
e.g. chat application

I will cover advanced Javascript topics like Promises, Web Worker and Web
Sockets in my next article.

Mais conteúdo relacionado

Último

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
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
(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
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
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 Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 

Último (20)

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
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
(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...
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
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 Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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
 

Destaque

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Destaque (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Exam 70 480 Javascript at Jinal Desai .NET

  • 1. Articles from Jinal Desai .NET Exam 70-480 Javascript 2013-01-20 14:01:22 Jinal Desai The article is intended for Microsoft Certification Exam 70-480 aspirants. All the points covered in this article is described from exam 70-480 point of view only. Some advanced topics like Promises, Web Worker, Web Sockets will be covered in my next article. Variable Types string, number, boolean, array, objects, null, undefined Functions Callable Behaviors Implemented as Objects Hoisting: Call functions before they are defined is called hoisting. f1(); function f1() { alert(“f1”); } Function Arguments Internally Passed: Contains all the arguments in “arguments” array variable. Function Scope e.g. var ops={ add:function addNumbers(n1, n2) { } } var x = ops.add(5,8); //valid var y = ops.addNumbers(5, 8); //Invalid //Function addNumbers can be called internally but not from outside e.g. function outer(n) { function inner() { return n*n; } return inner(); } Immediate Functions Immediate functions called automatically, no need to call it explicitly. (function(){ }()); or (function(){})();
  • 2. Function as argument function add(n1, n2) { return n1+n2; } function calc(proc, n1, n2) { return proc(n1, n2); } calc(add, 5, 8); Arrays Array functions: push, pop, concat, map, filter, some, every, forEach, reduce, sort, splice, join, reverse var x=[]; var y=[6]; var fruit=[“apple”,”banana”]; fruit.push(“orange”); var orange = fruit.pop(); var otherFruit = [“banana”]; fruit = fruit.concat(otherFruit); var apple = fruit.splice(0,1); //0 to 1 items, 0 based array var malon = fruit.splice(3,1,”malon”,”grapes”); //it will splice 4th item Array Projections fruit=fruit.map(function(i) { return i.toUpperCase(); }); fruit=fruit.map(function(i){ return{ FruitName: i.toUpperCase(); }); fruit=fruit.filter(function(i){ return i[0]===’a'; }); bool result = fruit.every(function(i){ return i[0]===’a'; }); //returns true if every fruit name starts with ‘a’ bool result = fruit.every(function(i){ return i.length>0 }); //returns true if all the fruit name length is greater than 0. bool result = fruit.some(function(i){ return i[0]===’a'; }); //returns true if some of the fruits starts with ‘a’. var length=[];
  • 3. fruit.forEach(function(i){ length[counter++]=i.length; }); Objects in Javascript var obj = { }; obj.FirstName=”Jinal”; obj.SayHello=function(){ alert(“Hello”); }; or var obj = { FirstName = “Jinal”, SayHello=function(){ alert(“Hello”); } }; DOM Interactions Quering the DOM var x = document.getElementById(“anyId”); or var x = document.getElementById(“#anyId”); var y = document.getElementByTagName(“h1”); var z = document.querySelector(“.item”); var collection = document.querySelectorAll(“.className”); Manipulating DOM var x = document.querySelector(“#anyId”); x.innerText = “changed inner text”; x.className = “NewClassName”; x.classList.add(“item”); Responding to events Declarative <button id=”button” onclick=”handler();”>Click Here</button> //Javascript function handler(){ } Programmatic var b=document.querySelector(“#button”); b.addEventListener(“click”,handler); or b.onclick=handler; or //anonymous function b.onclick=function(){ } Remove event listener programmatically b.removeEventListener(“click”, handler);
  • 4. It is not possible to remove event once it is bind using declarative method. Advanced Topics Handling Exceptions Two ways: Managing failure in code or minimizing failure in code. How to manage failure in code? Try{ } catch(e){ } finally{ } function throwHelper(){ var error = new Error(123, “error”); throw error; } try{ throwHelper(); } catch(error){ var msg=error.number + “ : “ + error.message; } Another way to throw error in windows is throw new WinJS.ErrorFromName(“args”,”error”); Promises Asynchronous Call WinJS.xhr((url=”url”, headers={Accept:”application/json”}).then( function(xhr){ var result = JSON.parse(xhr.response);}); Web Worker WinJS.UI.Pages.define(“/pages/webworker/webworker.html”, {ready:function(element,options){ var worker=new worker(“/pages/webworker/task.js”); worker.onmessage=function(e){ logMessage(“The worker process said “ + e.message); }; worker.postMessage(“Hey there, how are you?”); } }; //task.js self.onMessage=function(e){ self.postMessage(“I am away “ + e.data); };
  • 5. Web Socket It allows to talk to lower level http. e.g. chat application I will cover advanced Javascript topics like Promises, Web Worker and Web Sockets in my next article.