Exam 70 480 Javascript at Jinal Desai .NET

1,276 views
1,107 views

Published on

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.

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

  • Be the first to like this

No Downloads
Views
Total views
1,276
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
42
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Exam 70 480 Javascript at Jinal Desai .NET

  1. 1. Articles from Jinal Desai .NETExam 70-480 Javascript2013-01-20 14:01:22 Jinal DesaiThe article is intended for Microsoft Certification Exam 70-480 aspirants. All thepoints 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 inmy next article.Variable Typesstring, number, boolean, array, objects, null, undefinedFunctionsCallable BehaviorsImplemented as ObjectsHoisting: Call functions before they are defined is called hoisting.f1();function f1() {alert(“f1”);}Function ArgumentsInternally Passed: Contains all the arguments in “arguments” array variable.Function Scopee.g.var ops={add:function addNumbers(n1, n2) {}}var x = ops.add(5,8); //validvar y = ops.addNumbers(5, 8); //Invalid//Function addNumbers can be called internally but not from outsidee.g.function outer(n) {function inner() {return n*n;}return inner();}Immediate FunctionsImmediate functions called automatically, no need to call it explicitly.(function(){ }());or(function(){})();
  2. 2. Function as argumentfunction add(n1, n2) {return n1+n2;}function calc(proc, n1, n2) {return proc(n1, n2);}calc(add, 5, 8);ArraysArray functions:push, pop, concat, map, filter, some, every, forEach, reduce, sort, splice, join,reversevar 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 arrayvar malon = fruit.splice(3,1,”malon”,”grapes”); //it will splice 4th itemArray Projectionsfruit=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. 3. fruit.forEach(function(i){length[counter++]=i.length;});Objects in Javascriptvar obj = { };obj.FirstName=”Jinal”;obj.SayHello=function(){ alert(“Hello”); };orvar obj = {FirstName = “Jinal”,SayHello=function(){ alert(“Hello”); }};DOM InteractionsQuering the DOMvar x = document.getElementById(“anyId”);orvar x = document.getElementById(“#anyId”);var y = document.getElementByTagName(“h1”);var z = document.querySelector(“.item”);var collection = document.querySelectorAll(“.className”);Manipulating DOMvar x = document.querySelector(“#anyId”);x.innerText = “changed inner text”;x.className = “NewClassName”;x.classList.add(“item”);Responding to eventsDeclarative<button id=”button” onclick=”handler();”>Click Here</button>//Javascriptfunction handler(){}Programmaticvar b=document.querySelector(“#button”);b.addEventListener(“click”,handler);orb.onclick=handler;or//anonymous functionb.onclick=function(){}Remove event listener programmaticallyb.removeEventListener(“click”, handler);
  4. 4. It is not possible to remove event once it is bind using declarative method.Advanced TopicsHandling ExceptionsTwo 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 isthrow new WinJS.ErrorFromName(“args”,”error”);PromisesAsynchronous CallWinJS.xhr((url=”url”, headers={Accept:”application/json”}).then(function(xhr){var result = JSON.parse(xhr.response);});Web WorkerWinJS.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.jsself.onMessage=function(e){self.postMessage(“I am away “ + e.data);};
  5. 5. Web SocketIt allows to talk to lower level http.e.g. chat applicationI will cover advanced Javascript topics like Promises, Web Worker and WebSockets in my next article.

×