SlideShare a Scribd company logo
1 of 18
Download to read offline
JavaScript for C# Developers
By Sarvesh Kushwaha
What JavaScript Is ? But its not C#
• Strongly Typed and Compiled
• Classical Inheritance
• Classes
• Constructors
• Methods
• Loosely Typed and Dynamic
• Prototypal
• Functions
• Functions
• Functions
C# JavaScript
JavaScript Types
JavaScript has basic types :
 Value Types
 Boolean
 String
 Number
 Reference Types
 Object
 Delegate type
 Function
 Special type
 undefined
 null
var z = y // undefined
var x = null // null
var x = typeof 1 // number
var z = typeof 1.0 // number
var y = typeof true // Boolean
Var c = type of “I m sick of this hello world” //
String
var x = new Object(); // object
var z = new Array(); //object
var f = function(arg1, arg2) {};
// f(1,2); its like func<> in C#.
JavaScript Types Contd..
• Type Coalescing
• Type Detection
“Hi ” + “All” // Hi All (string)
“Hi ” + 1 // Hi 1 (string)
1 + “2025” // 12025 (number)
var x = 1;
var typeName = type of x ; // number
All About JavaScript Functions
• Functions is just an object which has properties and member functions
• Functions can store as variable like anonymous function in C#
function SayHello(s) { alert(“Hello”);}
var a = SayHello.length; // 1 parameter
var b = SayHello.toString(); // return whole function as string
var a = function(s) {alert (“Hello”);}
a(1); //call like a function
a.length; //1
All About JavaScript Functions
• Functions parameters do not matters
• No Overloading
function test(a,b,c)
{ alert(a);
alert(b); alert(c);
}
test(1); // b , c will simply undefined
function foo(a)
{ alert(“Hello”); }
function foo(b,c)
{ alert(“Bye”); }
foo(1); // Bye  huh ?
All About JavaScript Functions
• Arguments object , Remember params in C# ?
function foo(a,b,c)
{
alert(arugments.length);
}
foo (1); // 1
// pass many parameters and access their values
function foo()
{
for(var i = 0;i < arguments.length;i++ )
{
alert(arguments[i]);
}
}
foo(1,2,3);
All About JavaScript Functions
• Function always return a value
• ‘this’ tells the owner of the function
• Supports Closure
function foo(a,b,c){ } // will return undefined
var a = foo() // type of ‘undefined’
function foo(a,b,c){ return; } // will return undefined
function foo(a,b,c){ return “”; } // will return s
var anyobj = { name : “Sarvesh”,
func : function(){ console.log(this.name); }}
anyobj.func() // “Sarvesh”
var x= 1;
function anyfunction() { var y = x; }
//references outside of function remains regardless of lifetime
JavaScript Scope
• Functions creates scope
var a = 1; // Global Scope , Added to window object
function abc()
{
var b = a; //works because of closure , and b is limit to
this function only
}
var c = b; // that will not work
JavaScript Namespacing
• Create a namespace
//Don’t have namespace we can mimic them by
creating a object
// Import namespaces or create a new one
var MyNamespace = MyNamespace || {};
MyNamespace.CurrentDate = function() {
return new Date();
}
JavaScript as Object Oriented language
• Classes : No such thing available in JavaScript , but you can mimic it.
function Employee(name ,department)
{
// public properties
this.name = name;
this.department = department;
//member function
this.creditSalary = function(amount){};
// private properties
var annualPackage = 10000;
}
var emp = new Employee(“Sarvesh”,”Development”);
var getDep = emp.department;
emp.creditSalary(1000);
JavaScript as Object Oriented language
• Read & Write , Read only and Write only properties :
function Employee(name)
{
var _name = name;
Object.defineProperty(this,”name”, {
get : function() { return _name;},
set: function(value) {_name = value;} //don’t include set to make
it read only
});
}
var emp = new Employee(“Sarvesh”);
var name = emp.name;
JavaScript as Object Oriented language
• Static Members
function Employee(name ,department)
{
// public properties
this.name = name;
this.department = department;
}
Employee.Married = “Single”;
var emp = new Employee(“Sarvesh”,”Development”);
var getMarriedStatus = emp.Married; //will not work
getMarriedStatus = Employee.Married; //work
JavaScript as Prototype language
• Why its called prototype language ? Because every object you create in
JavaScript has a prototype object.
• All instance of object shares the prototype members.
• Prototype can be used to add extension methods
function Employee(name ,department)
{// public properties
this.name = name;
this.department = department;
}
Employee.prototype.Married = “Single”;
var emp = new Employee(“Sarvesh”,”Development”);
var getMarriedStatus = emp.Married; //now it will work
Array.prototype.detectLength = function() {return this.length;};
Var a = [“One”,”Two”];
var getLength = a.DetectLength();
Reflection in JavaScript
• Like C# , JavaScript allows us to enumerate members
var Emp= {
name : “Sarvesh”,
Companyname : “Microsoft”,
sendThanks : function() {}
};
for(var property in Emp ) //Object reflection
{
alert(property); // name
alert(Emp[property]); // value
}
//Detect properties
var a = new Employee();
var has = a.hasOwnProperty(“name”); //will return Bool value
var isEnum = a.propertyIsEnumerable(“name”);
Architecting JavaScript files
• Isolates scripts with namespaces
<html>
<script src=“One.js”></script>
<script src=“two.js”></script>
</html>
(function(ns){
ns.customer = function(){
this.name = “”;
};
}(window.mynamespace = window.mynamespace || {} ));
(function(ns){
ns.Emp = function(){
this.name = “”;
};
}(window.mynamespace = window.mynamespace || {} ));
Things which are important to know in
Javascript
• Strict Mode (Use of undefined variable, No Duplicate property name, Cant assign
value to read only property)
• Foreach in C# is diff from JavaScript For-In
• Use JS lint in Visual Studio for Compilation Check
“use strict”;
var a = “hiii”; // will work
y = “hii”; // it will not work
var x = {Salary : “” , Salary : “”} // exception
x.Length = 5; //exception
var a = [“A” , “B” , “C”];
for(var i in a)
{
console.log(i); // 0,1,2 will give index
console.log(a[i]); } // A, B, C
Sarvesh Kushwaha | | | | | |

More Related Content

What's hot

LINQ Inside
LINQ InsideLINQ Inside
LINQ Insidejeffz
 
Learn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik CubeLearn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik CubeManoj Kumar
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
Angular 2.0: Brighter future?
Angular 2.0: Brighter future?Angular 2.0: Brighter future?
Angular 2.0: Brighter future?Eugene Zharkov
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...DevClub_lv
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?Sarah Mount
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
Maintainable JavaScript
Maintainable JavaScriptMaintainable JavaScript
Maintainable JavaScriptNicholas Zakas
 
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...MongoDB
 
Mirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby GroupMirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby Groupbaroquebobcat
 
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
 
使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架jeffz
 
JavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closuresJavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closuresHDR1001
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptMichael Girouard
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - OperatorsWebStackAcademy
 

What's hot (20)

LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
 
Learn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik CubeLearn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik Cube
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Angular 2.0: Brighter future?
Angular 2.0: Brighter future?Angular 2.0: Brighter future?
Angular 2.0: Brighter future?
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Maintainable JavaScript
Maintainable JavaScriptMaintainable JavaScript
Maintainable JavaScript
 
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
 
Mirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby GroupMirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby Group
 
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
 
使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架
 
JavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closuresJavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closures
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 

Similar to JavaScript For CSharp Developer

The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming PrimerMike Wilcox
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almostQuinton Sheppard
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroAdam Crabtree
 
Javascript basics
Javascript basicsJavascript basics
Javascript basicsSolv AS
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Mario Camou Riveroll
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptDhruvin Shah
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app developmentopenak
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLê Thưởng
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: ServersidenessWebExpo
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
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 JavascriptMassimo Franciosa
 

Similar to JavaScript For CSharp Developer (20)

The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming Primer
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: Intro
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app development
 
Let's JavaScript
Let's JavaScriptLet's JavaScript
Let's JavaScript
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Dart
DartDart
Dart
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
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
 

Recently uploaded

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 

Recently uploaded (20)

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 

JavaScript For CSharp Developer

  • 1. JavaScript for C# Developers By Sarvesh Kushwaha
  • 2. What JavaScript Is ? But its not C# • Strongly Typed and Compiled • Classical Inheritance • Classes • Constructors • Methods • Loosely Typed and Dynamic • Prototypal • Functions • Functions • Functions C# JavaScript
  • 3. JavaScript Types JavaScript has basic types :  Value Types  Boolean  String  Number  Reference Types  Object  Delegate type  Function  Special type  undefined  null var z = y // undefined var x = null // null var x = typeof 1 // number var z = typeof 1.0 // number var y = typeof true // Boolean Var c = type of “I m sick of this hello world” // String var x = new Object(); // object var z = new Array(); //object var f = function(arg1, arg2) {}; // f(1,2); its like func<> in C#.
  • 4. JavaScript Types Contd.. • Type Coalescing • Type Detection “Hi ” + “All” // Hi All (string) “Hi ” + 1 // Hi 1 (string) 1 + “2025” // 12025 (number) var x = 1; var typeName = type of x ; // number
  • 5. All About JavaScript Functions • Functions is just an object which has properties and member functions • Functions can store as variable like anonymous function in C# function SayHello(s) { alert(“Hello”);} var a = SayHello.length; // 1 parameter var b = SayHello.toString(); // return whole function as string var a = function(s) {alert (“Hello”);} a(1); //call like a function a.length; //1
  • 6. All About JavaScript Functions • Functions parameters do not matters • No Overloading function test(a,b,c) { alert(a); alert(b); alert(c); } test(1); // b , c will simply undefined function foo(a) { alert(“Hello”); } function foo(b,c) { alert(“Bye”); } foo(1); // Bye  huh ?
  • 7. All About JavaScript Functions • Arguments object , Remember params in C# ? function foo(a,b,c) { alert(arugments.length); } foo (1); // 1 // pass many parameters and access their values function foo() { for(var i = 0;i < arguments.length;i++ ) { alert(arguments[i]); } } foo(1,2,3);
  • 8. All About JavaScript Functions • Function always return a value • ‘this’ tells the owner of the function • Supports Closure function foo(a,b,c){ } // will return undefined var a = foo() // type of ‘undefined’ function foo(a,b,c){ return; } // will return undefined function foo(a,b,c){ return “”; } // will return s var anyobj = { name : “Sarvesh”, func : function(){ console.log(this.name); }} anyobj.func() // “Sarvesh” var x= 1; function anyfunction() { var y = x; } //references outside of function remains regardless of lifetime
  • 9. JavaScript Scope • Functions creates scope var a = 1; // Global Scope , Added to window object function abc() { var b = a; //works because of closure , and b is limit to this function only } var c = b; // that will not work
  • 10. JavaScript Namespacing • Create a namespace //Don’t have namespace we can mimic them by creating a object // Import namespaces or create a new one var MyNamespace = MyNamespace || {}; MyNamespace.CurrentDate = function() { return new Date(); }
  • 11. JavaScript as Object Oriented language • Classes : No such thing available in JavaScript , but you can mimic it. function Employee(name ,department) { // public properties this.name = name; this.department = department; //member function this.creditSalary = function(amount){}; // private properties var annualPackage = 10000; } var emp = new Employee(“Sarvesh”,”Development”); var getDep = emp.department; emp.creditSalary(1000);
  • 12. JavaScript as Object Oriented language • Read & Write , Read only and Write only properties : function Employee(name) { var _name = name; Object.defineProperty(this,”name”, { get : function() { return _name;}, set: function(value) {_name = value;} //don’t include set to make it read only }); } var emp = new Employee(“Sarvesh”); var name = emp.name;
  • 13. JavaScript as Object Oriented language • Static Members function Employee(name ,department) { // public properties this.name = name; this.department = department; } Employee.Married = “Single”; var emp = new Employee(“Sarvesh”,”Development”); var getMarriedStatus = emp.Married; //will not work getMarriedStatus = Employee.Married; //work
  • 14. JavaScript as Prototype language • Why its called prototype language ? Because every object you create in JavaScript has a prototype object. • All instance of object shares the prototype members. • Prototype can be used to add extension methods function Employee(name ,department) {// public properties this.name = name; this.department = department; } Employee.prototype.Married = “Single”; var emp = new Employee(“Sarvesh”,”Development”); var getMarriedStatus = emp.Married; //now it will work Array.prototype.detectLength = function() {return this.length;}; Var a = [“One”,”Two”]; var getLength = a.DetectLength();
  • 15. Reflection in JavaScript • Like C# , JavaScript allows us to enumerate members var Emp= { name : “Sarvesh”, Companyname : “Microsoft”, sendThanks : function() {} }; for(var property in Emp ) //Object reflection { alert(property); // name alert(Emp[property]); // value } //Detect properties var a = new Employee(); var has = a.hasOwnProperty(“name”); //will return Bool value var isEnum = a.propertyIsEnumerable(“name”);
  • 16. Architecting JavaScript files • Isolates scripts with namespaces <html> <script src=“One.js”></script> <script src=“two.js”></script> </html> (function(ns){ ns.customer = function(){ this.name = “”; }; }(window.mynamespace = window.mynamespace || {} )); (function(ns){ ns.Emp = function(){ this.name = “”; }; }(window.mynamespace = window.mynamespace || {} ));
  • 17. Things which are important to know in Javascript • Strict Mode (Use of undefined variable, No Duplicate property name, Cant assign value to read only property) • Foreach in C# is diff from JavaScript For-In • Use JS lint in Visual Studio for Compilation Check “use strict”; var a = “hiii”; // will work y = “hii”; // it will not work var x = {Salary : “” , Salary : “”} // exception x.Length = 5; //exception var a = [“A” , “B” , “C”]; for(var i in a) { console.log(i); // 0,1,2 will give index console.log(a[i]); } // A, B, C
  • 18. Sarvesh Kushwaha | | | | | |