SlideShare a Scribd company logo
2
Most read
3
Most read
4
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
ReactJS presentation.pptx
PDF
Spring Boot
PDF
The Point of Vue - Intro to Vue.js
PDF
ES6 presentation
PPTX
Introduction to Spring Boot
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
PDF
Kotlin for Android Development
PPTX
Angular interview questions
ReactJS presentation.pptx
Spring Boot
The Point of Vue - Intro to Vue.js
ES6 presentation
Introduction to Spring Boot
Asynchronous JavaScript Programming with Callbacks & Promises
Kotlin for Android Development
Angular interview questions

What's hot (20)

PPTX
JavaFX Presentation
PDF
Spring boot introduction
PPTX
Apache tomcat
PPTX
Top 20 c# interview Question and answers
PPTX
Awt, Swing, Layout managers
PDF
Kotlin Coroutines and Android sitting in a tree
PPT
Spring Core
PDF
Understanding react hooks
PDF
Spring Boot
PPTX
Node.js Express
PPT
Java And Multithreading
PPTX
Spring boot
PDF
PPTX
Basic Concept of Node.js & NPM
PPT
PPS
Java Hibernate Programming with Architecture Diagram and Example
PPT
Jsp ppt
PDF
Basics of React Hooks.pptx.pdf
PPTX
ASP.NET MVC Presentation
PPTX
Spring boot
JavaFX Presentation
Spring boot introduction
Apache tomcat
Top 20 c# interview Question and answers
Awt, Swing, Layout managers
Kotlin Coroutines and Android sitting in a tree
Spring Core
Understanding react hooks
Spring Boot
Node.js Express
Java And Multithreading
Spring boot
Basic Concept of Node.js & NPM
Java Hibernate Programming with Architecture Diagram and Example
Jsp ppt
Basics of React Hooks.pptx.pdf
ASP.NET MVC Presentation
Spring boot
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
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
Spectroscopy.pptx food analysis technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
MYSQL Presentation for SQL database connectivity
Programs and apps: productivity, graphics, security and other tools
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
MIND Revenue Release Quarter 2 2025 Press Release

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