SlideShare a Scribd company logo
2
Most read
3
Most read
11
Most read
Advanced JavaScript
Dhruvin Shah
Agenda
• Hoisting and Strict Mode
• Functions as Objects
• Best Practices
• Objects and Prototypes
• Functions
• Closures
• Important Javascript Functions
• Javascript Global Objects
• Javascript Versions
Hoisting
• Moving declarations on top of the current
scope
• Only declarations and not initializations
• This can lead to errors and bugs in code if
unaware about variables
• Solution ?
Use Strict
• "use strict";
• Declared at the beginning of a script, it has
global scope
• Recognized only at the beginning of a script
• Introduced since ECMA 5
Best Practices
• Avoid Global variables
– Use strict mode to detect undeclared variables
– Use Closures
• Declarations and Initializations on top to avoid
undefined values
• Don’t declare type of variables
• Use === Comparison
• Don’t use eval()
• Try using for .. in instead of conventional for
Examples
var x = 5 + 7;
var x = 5 + "7";
var x = "5" + 7;
var x = 5 - 7;
var x = 5 - "7";
var x = "5" - 7;
var x = 5 - "x";
var x = 2 * "7";
var x = 2 * "x";
Objects and Prototypes
• Objects – Properties and Methods
• var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue“,
fullName: function(){
return this.firstName + “ ” +
this.lastName;
}
Functions
• Anonymous functions
e.g. var x = function (a, b) {return a * b};
• Self Invoking Function
e.g. (function () {
var x = "Hello!!"; // self invoke
})();
• Does not check the number of parameters
passed when invoked
Closures
• Global variables can be made local (private)
with closures.
function makeFunc() {
var name = 'Mozilla';
function displayName() {
alert(name);
}
return displayName;
}
var myFunc = makeFunc();
Important Javascript Functions
Call vs Apply vs Bind
Parameter Call Apply Bind
Definition calls a function with
a given this value
and arguments
provided
individually
calls a function with
a given this value,
and arguments pro
vided as an array
(or an array-like
object
Function gets
executed when
event is triggered
or some condition
is satisfied
Syntax function.call(thisArg
, arg1, arg2, ...)
fun.apply(thisArg,
[argsArray])
fun.bind(thisArg[,
arg1[, arg2[, ...]]])
• setTimeout(func, millisec) => returns ID
• clearTimeout(ID)
• setInterval(func, millisec) => returns ID
• clearInterval(ID)
• this variable is not accessible while using
Timing Events
• Solution ?
Timing Events
• window – open, close, moveTo, resizeTo
• screen – height, width, pixel depth
• location –
window.location.href
window.location.hostname
window.location.pathname
window.location.protocol
window.location.assign
• history – back, forward
• navigator – browser information
Javascript Global Objects
• Device API
− Light sensor
− Battery
− Geolocation
− Device Orientation
− Screen Orientation
• Communication API
− Notification
− Network
• Data management
Web API
JavascriptVersion
• Arrow Functions
• Typescript
Further Reading
Sources
• W3schools.com
• Mozilla Developer network

More Related Content

PPTX
PPTX
Présentation de ECMAScript 6
PDF
Introduction à React
PDF
PDF
jQuery - Chapter 1 - Introduction
PDF
Javascript
PDF
Introduction to Java
PDF
JPA and Hibernate
Présentation de ECMAScript 6
Introduction à React
jQuery - Chapter 1 - Introduction
Javascript
Introduction to Java
JPA and Hibernate

What's hot (20)

PPTX
Introduction à React
PPTX
A Brief Introduction to React.js
PPT
Advanced Javascript
PDF
Scalable JavaScript Application Architecture
PPTX
React web development
PPTX
Introduction to JavaScript Basics.
PPT
Introduction to Javascript
PDF
Angular - Chapter 4 - Data and Event Handling
PPTX
Introduction to React JS
PPTX
Intro to React
PPTX
JavaScript Basics
PPTX
React-JS.pptx
PPTX
Angular introduction students
PPTX
Spring boot - an introduction
PPTX
React js programming concept
PDF
Understanding react hooks
PDF
Introduction à Angular 2
PPTX
react-slides.pptx
PDF
Angular - Chapter 7 - HTTP Services
Introduction à React
A Brief Introduction to React.js
Advanced Javascript
Scalable JavaScript Application Architecture
React web development
Introduction to JavaScript Basics.
Introduction to Javascript
Angular - Chapter 4 - Data and Event Handling
Introduction to React JS
Intro to React
JavaScript Basics
React-JS.pptx
Angular introduction students
Spring boot - an introduction
React js programming concept
Understanding react hooks
Introduction à Angular 2
react-slides.pptx
Angular - Chapter 7 - HTTP Services
Ad

Similar to Advanced Javascript (20)

PPTX
Object oriented java script
PPTX
Lecture 4- Javascript Function presentation
PPTX
JavaScript- Functions and arrays.pptx
PPTX
Awesomeness of JavaScript…almost
PPTX
Javascript analysis
PDF
JavaScript: Patterns, Part 3
PPTX
11_Functions_Introduction.pptx javascript notes
PDF
JavaScript
PDF
Fii Practic Frontend - BeeNear - laborator3
PDF
java script functions, classes
PDF
Rediscovering JavaScript: The Language Behind The Libraries
PPTX
javaScript and jQuery
PDF
[2015/2016] JavaScript
PPTX
Lecture 5: Client Side Programming 1
PPTX
Advance JS and oop
PPT
25-functions.ppt
PPT
Object Oriented JavaScript
PPT
JavaScript - Programming Languages course
PPTX
Intro to Javascript
PPT
A Deeper look into Javascript Basics
Object oriented java script
Lecture 4- Javascript Function presentation
JavaScript- Functions and arrays.pptx
Awesomeness of JavaScript…almost
Javascript analysis
JavaScript: Patterns, Part 3
11_Functions_Introduction.pptx javascript notes
JavaScript
Fii Practic Frontend - BeeNear - laborator3
java script functions, classes
Rediscovering JavaScript: The Language Behind The Libraries
javaScript and jQuery
[2015/2016] JavaScript
Lecture 5: Client Side Programming 1
Advance JS and oop
25-functions.ppt
Object Oriented JavaScript
JavaScript - Programming Languages course
Intro to Javascript
A Deeper look into Javascript Basics
Ad

Recently uploaded (20)

PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
KodekX | Application Modernization Development
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Top Generative AI Tools for Patent Drafting in 2025.pdf
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PPTX
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
PPTX
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Dell Pro 14 Plus: Be better prepared for what’s coming
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
KodekX | Application Modernization Development
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Top Generative AI Tools for Patent Drafting in 2025.pdf
Reimagining Insurance: Connected Data for Confident Decisions.pdf
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Modernizing your data center with Dell and AMD
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Enable Enterprise-Ready Security on IBM i Systems.pdf
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
GamePlan Trading System Review: Professional Trader's Honest Take
Dell Pro 14 Plus: Be better prepared for what’s coming

Advanced Javascript

  • 2. Agenda • Hoisting and Strict Mode • Functions as Objects • Best Practices • Objects and Prototypes • Functions • Closures • Important Javascript Functions • Javascript Global Objects • Javascript Versions
  • 3. Hoisting • Moving declarations on top of the current scope • Only declarations and not initializations • This can lead to errors and bugs in code if unaware about variables • Solution ?
  • 4. Use Strict • "use strict"; • Declared at the beginning of a script, it has global scope • Recognized only at the beginning of a script • Introduced since ECMA 5
  • 5. Best Practices • Avoid Global variables – Use strict mode to detect undeclared variables – Use Closures • Declarations and Initializations on top to avoid undefined values • Don’t declare type of variables • Use === Comparison • Don’t use eval() • Try using for .. in instead of conventional for
  • 6. Examples var x = 5 + 7; var x = 5 + "7"; var x = "5" + 7; var x = 5 - 7; var x = 5 - "7"; var x = "5" - 7; var x = 5 - "x"; var x = 2 * "7"; var x = 2 * "x";
  • 7. Objects and Prototypes • Objects – Properties and Methods • var person = { firstName:"John", lastName:"Doe", age:50, eyeColor:"blue“, fullName: function(){ return this.firstName + “ ” + this.lastName; }
  • 8. Functions • Anonymous functions e.g. var x = function (a, b) {return a * b}; • Self Invoking Function e.g. (function () { var x = "Hello!!"; // self invoke })(); • Does not check the number of parameters passed when invoked
  • 9. Closures • Global variables can be made local (private) with closures. function makeFunc() { var name = 'Mozilla'; function displayName() { alert(name); } return displayName; } var myFunc = makeFunc();
  • 11. Call vs Apply vs Bind Parameter Call Apply Bind Definition calls a function with a given this value and arguments provided individually calls a function with a given this value, and arguments pro vided as an array (or an array-like object Function gets executed when event is triggered or some condition is satisfied Syntax function.call(thisArg , arg1, arg2, ...) fun.apply(thisArg, [argsArray]) fun.bind(thisArg[, arg1[, arg2[, ...]]])
  • 12. • setTimeout(func, millisec) => returns ID • clearTimeout(ID) • setInterval(func, millisec) => returns ID • clearInterval(ID) • this variable is not accessible while using Timing Events • Solution ? Timing Events
  • 13. • window – open, close, moveTo, resizeTo • screen – height, width, pixel depth • location – window.location.href window.location.hostname window.location.pathname window.location.protocol window.location.assign • history – back, forward • navigator – browser information Javascript Global Objects
  • 14. • Device API − Light sensor − Battery − Geolocation − Device Orientation − Screen Orientation • Communication API − Notification − Network • Data management Web API
  • 16. • Arrow Functions • Typescript Further Reading Sources • W3schools.com • Mozilla Developer network