SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
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 | | | | | |

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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 a 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 a 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
 

Último

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Último (20)

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

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 | | | | | |