SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
WEEKLY PRESENTATION
DURING TRAINING PROGRAM
- Devang Garach
devanggarach.rao@gmail.com
WEEK-6
Information Technology
AGENDA - Advanced JavaScript
Difference between let, var and const keyword
Destructuring array & objects
JavaScript Hoisting
JavaScript Arrow Function
JavaScript Async / Await
JavaScript Promises & Chaining
Callback Function
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Difference between let, var ,and constant keyword
var let const
It is available right from
the beginning when the
JavaScript was
introduced
It is a new way to declare
variables in JavaScript,
starting from ES6 or
ECMAScript 2015
const is used to store a
value that will not be
changed throughout the
execution of the script, it is
also introduced with ES6
It has a global/ function
scope
It has block scope It also has block scope
Can be updated or re-
declared in its scope
We can't re-declare them const represent a const
value, so it can't be
updated or re-declared
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Destructuring array & objects
The destructuring assignment is a cool feature that came along with ES6.
Destructuring is a JavaScript expression that makes it possible to unpack
values from arrays, or properties from objects, into distinct variables. That
is, we can extract data from arrays and objects and assign them to variables.
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Lets understand with example
Why it is important?
let introduction = ["Hello", "I" , "am", "Sarah"];
let greeting = introduction[0];
let name = introduction[3];
console.log(greeting); //"Hello"
console.log(name); //"Sarah"
(Source : freecodecamp.org)
Destructuring array & objects (Continue...)
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
example
Why it is important?
let introduction = ["Hello", "I" , "am", "Sarah"];
let [greeting, pronoun] = introduction;
console.log(greeting);//"Hello"
console.log(pronoun); //"I"
let [greeting, pronoun] = ["Hello", "I" , "am", "Sarah"];
console.log(greeting);//"Hello"
console.log(pronoun); //"I"
(Source : freecodecamp.org)
Destructuring array & objects (Continue...)
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
example
Why it is important?
let [greeting,,,name] = ["Hello", "I" , "am", "Sarah"];
console.log(greeting);//"Hello"
console.log(name); //"Sarah"
let [greeting,...intro] = ["Hello", "I" , "am", "Sarah"];
console.log(greeting);//"Hello"
console.log(intro); //["I", "am", "Sarah"]
(Source : freecodecamp.org)
Destructuring array & objects (Continue...)
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
example
Why it is important?
function getArray() {
return ["Hello", "I" , "am", "Sarah"];
}
let [greeting,pronoun] = getArray();
console.log(greeting);//"Hello"
console.log(pronoun);//"I"
let a = 3;
let b = 6;
[a,b] = [b,a];
console.log(a);//6
console.log(b);//3
(Source : freecodecamp.org)
Destructuring array & objects (Continue...)
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
let person = {name: "Sarah", country: "Nigeria", job: "Developer"};
let name = person.name;
let country = person.country;
let job = person.job;
console.log(name);//"Sarah"
console.log(country);//"Nigeria"
console.log(job);//Developer"
let person = {name: "Sarah", country: "Nigeria", job: "Developer"};
let {name:foo = "myName", friend: bar = "Annie"} = person;
console.log(foo);//"Sarah"
console.log(bar);//"Annie"
(Source : freecodecamp.org)
Destructuring array & objects (Continue...)
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
example
Why it is important?
let person = {name: "Sarah", country: "Nigeria", job: "Developer"};
let name, country, job; {name, country, job} = person;
console.log(name); // Error : "Unexpected token ="
let person = {name: "Sarah", country: "Nigeria", job: "Developer"};
let name, country, job;
({name, country, job} = person);
console.log(name); //"Sarah"
console.log(job); //"Developer"
(Source : freecodecamp.org)
JavaScript Hoisting
Hoisting is JavaScript's default behavior of moving declarations to the top
In JavaScript, a variable can be declared after it has been used. In other words; a variable
can be used before it has been declared
Not only variables but also function declarations are moved to the top of their scope
before code execution
JavaScript only hoists declarations, not initializations.
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Example:
x = 5; // Assign 5 to x
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x; // Display x in the element
var x; // Declare x
JavaScript Arrow Function
Arrow functions were introduced in ES6.
Arrow functions allow us to write shorter function syntax:
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Before Arrow function:
hello = function(){
return "Hello World!";
}
After Arrow function:
hello = () => {
return "Hello World!";
}
hello = () => "Hello World!"; hello = (val) => "Hello " + val;
Arrow Functions Return Value by Default: Arrow Functions with parameters
hello = val => "Hello " + val;
Arrow Functions without parentheses (Source : w3schools.com)
JavaScript Async / Await
JavaScript is asynchronous, it never wait for anyone.
Functions running in parallel with other functions are called asynchronous
JavaScript will move on without waiting some process to finish.
“async and await make promises easier to write"
async makes a function return a Promise,
await makes a function wait for a Promise
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Example:
async function myFunction() {
return Promise.resolve("Hello");
}
The keyword async before a function makes the function return a promise: (Source : w3schools.com)
JavaScript Async / Await (Continue...)
Await Syntax:
The keyword await before a function makes the function wait for a promise:
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
let value = await promise
The await keyword can only be used inside an async function.
Example:
async function myDisplay() {
let myPromise = new Promise(function(myResolve, myReject) {
myResolve("I love JavaScript!!");
});
document.getElementById("demo").innerHTML = await myPromise;
}
myDisplay();
(Source : w3schools.com)
JavaScript Promises
As we all know that JavaScript is an asynchronous scripting language.
Promises are used to handle asynchronous operations in JavaScript. They
are easy to manage when dealing with multiple asynchronous operations
where callbacks can create callback hell leading to unmanageable code.
Benefits of Promises
● Improves Code Readability
● Better handling of asynchronous operations
● Better flow of control definition in asynchronous logic
● Better Error Handling
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
JavaScript Promises (Continue...)
A Promise has four states:
● fulfilled: Action related to the promise succeeded
● rejected: Action related to the promise failed
● pending: Promise is still pending i.e not fulfilled or rejected yet
● settled: Promise has fulfilled or rejected
A promise can be created using Promise constructor.
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Syntax:
var promise = new Promise(function(resolve, reject){
//do something
}
);
JavaScript Promises (Continue...)
Promise Consumers:
Promises can be consumed by registering functions using .then and .catch methods.
then() is invoked when a promise is either resolved or rejected.
Parameters: then() method takes two functions as parameters. Success or Error.
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Example:
var promise = new Promise(function(resolve, reject) {
resolve('Hi its Resolved, Success');
})
promise.then(
function(successMessage) {
//success handler function is invoked
console.log(successMessage);
}, function(errorMessage) {
console.log(errorMessage);
});
(Source : geeksforgeeks.org)
JavaScript Promises (Continue...)
Promises Methods:
Promise.all([array])
If the returned promise resolves, it is resolved with an aggregating array of
the values from the resolved promises, in the same order as defined in the
iterable of multiple promises. If it rejects, it is rejected with the reason from
the first promise in the iterable that was rejected.
Promise.allSettled()
Wait until all promises have settled (each may resolve or reject). Returns a
Promise that resolves after all of the given promises have either resolved or
rejected, with an array of objects that each describe the outcome of each
promise.
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
(Source : w3schools.com)
JavaScript Promises (Continue...)
Promises Methods:
Promise.any():
Takes an iterable of Promise objects and, as soon as one of the promises in
the iterable fulfills, returns a single promise that resolves with the value
from that promise.
Promise.finally() - finally is an instance method like then() , catch()
Appends a handler to the promise, and returns a new promise that is
resolved when the original promise is resolved. The handler is called when
the promise is settled, whether fulfilled or rejected.
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
(Source : w3schools.com)
JavaScript Callback Function
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
(Source : freecodecamp.org)
Why do we need Callback Functions?
JavaScript runs code sequentially in top-down order. However, there are some cases that
code runs (or must run) after something else happens and also not sequentially. This is
called asynchronous programming.
Callbacks make sure that a function is not going to run before a task is completed but will
run right after the task has completed. It helps us develop asynchronous JavaScript code
and keeps us safe from problems and errors.
In JavaScript, the way to create a callback function is to pass it as a parameter to another
function, and then to call it back right after something has happened or some task is
completed. Let's check an example.
JavaScript Callback Function (Continue...)
Callbacks are functions that we passed as an arguments to be invoked when
the callee has finished its job
Information Technology
DURING TRAINING PROGRAM - WEEKLY PRESENTATION
Example:
function myDisplayer(some) {
document.getElementById("demo").innerHTML = some;
}
function myCalculator(num1, num2, myCallback) {
let sum = num1 + num2;
myCallback(sum);
}
myCalculator(5, 5, myDisplayer); (Source : w3schools.com)
Thank You.
- Devang Garach
devanggarach.rao@gmail.com
Information Technology

Contenu connexe

Tendances

Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayChamnap Chhorn
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesDoris Chen
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesHùng Nguyễn Huy
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101ygv2000
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptzand3rs
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Annotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark ArtsAnnotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark ArtsJames Kirkbride
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic courseTran Khoa
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptStoyan Stefanov
 
JavaScript Execution Context
JavaScript Execution ContextJavaScript Execution Context
JavaScript Execution ContextJuan Medina
 
Even more java script best practices
Even more java script best practicesEven more java script best practices
Even more java script best practicesChengHui Weng
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic JavascriptBunlong Van
 

Tendances (20)

JavaScript OOPs
JavaScript OOPsJavaScript OOPs
JavaScript OOPs
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Object Oriented Javascript
Object Oriented JavascriptObject Oriented Javascript
Object Oriented Javascript
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented Way
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
Annotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark ArtsAnnotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark Arts
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
Spring boot
Spring bootSpring boot
Spring boot
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
JavaScript Execution Context
JavaScript Execution ContextJavaScript Execution Context
JavaScript Execution Context
 
Even more java script best practices
Even more java script best practicesEven more java script best practices
Even more java script best practices
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic Javascript
 

Similaire à Advanced JavaScript - Internship Presentation - Week6

Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & PromisesKnoldus Inc.
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APISalesforce Developers
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFXTom Mix Petreca
 
Arrows in commercial web applications
Arrows in commercial web applicationsArrows in commercial web applications
Arrows in commercial web applicationsAnirudh Gangwar
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxMegha V
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScriptAmitai Barnea
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Promises look into the async future
Promises look into the async futurePromises look into the async future
Promises look into the async futureslicejs
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.pptrani marri
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...Ben Teese
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfranjanadeore1
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observablesStefan Charsley
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashedJavier Arias Losada
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsAjax Experience 2009
 

Similaire à Advanced JavaScript - Internship Presentation - Week6 (20)

Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & Promises
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk API
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFX
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
React native
React nativeReact native
React native
 
Arrows in commercial web applications
Arrows in commercial web applicationsArrows in commercial web applications
Arrows in commercial web applications
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptx
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Promises look into the async future
Promises look into the async futurePromises look into the async future
Promises look into the async future
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation Goodparts
 

Plus de Devang Garach

AWS Concepts - Internship Presentation - week 10
AWS Concepts - Internship Presentation - week 10AWS Concepts - Internship Presentation - week 10
AWS Concepts - Internship Presentation - week 10Devang Garach
 
A glimpse inside of SEO - Internship Presentation - week 9
A glimpse inside of SEO - Internship Presentation - week 9A glimpse inside of SEO - Internship Presentation - week 9
A glimpse inside of SEO - Internship Presentation - week 9Devang Garach
 
Machine Learning and its types - Internship Presentation - week 8
Machine Learning and its types - Internship Presentation - week 8Machine Learning and its types - Internship Presentation - week 8
Machine Learning and its types - Internship Presentation - week 8Devang Garach
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Devang Garach
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Devang Garach
 
Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3Devang Garach
 
Basics of Linux Commands, Git and Github
Basics of Linux Commands, Git and GithubBasics of Linux Commands, Git and Github
Basics of Linux Commands, Git and GithubDevang Garach
 
M.C.A. Internship Project Presentation - Devang Garach [191823011]
M.C.A. Internship Project Presentation - Devang Garach [191823011]M.C.A. Internship Project Presentation - Devang Garach [191823011]
M.C.A. Internship Project Presentation - Devang Garach [191823011]Devang Garach
 

Plus de Devang Garach (8)

AWS Concepts - Internship Presentation - week 10
AWS Concepts - Internship Presentation - week 10AWS Concepts - Internship Presentation - week 10
AWS Concepts - Internship Presentation - week 10
 
A glimpse inside of SEO - Internship Presentation - week 9
A glimpse inside of SEO - Internship Presentation - week 9A glimpse inside of SEO - Internship Presentation - week 9
A glimpse inside of SEO - Internship Presentation - week 9
 
Machine Learning and its types - Internship Presentation - week 8
Machine Learning and its types - Internship Presentation - week 8Machine Learning and its types - Internship Presentation - week 8
Machine Learning and its types - Internship Presentation - week 8
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
 
Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3
 
Basics of Linux Commands, Git and Github
Basics of Linux Commands, Git and GithubBasics of Linux Commands, Git and Github
Basics of Linux Commands, Git and Github
 
M.C.A. Internship Project Presentation - Devang Garach [191823011]
M.C.A. Internship Project Presentation - Devang Garach [191823011]M.C.A. Internship Project Presentation - Devang Garach [191823011]
M.C.A. Internship Project Presentation - Devang Garach [191823011]
 

Dernier

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Dernier (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Advanced JavaScript - Internship Presentation - Week6

  • 1. WEEKLY PRESENTATION DURING TRAINING PROGRAM - Devang Garach devanggarach.rao@gmail.com WEEK-6 Information Technology
  • 2. AGENDA - Advanced JavaScript Difference between let, var and const keyword Destructuring array & objects JavaScript Hoisting JavaScript Arrow Function JavaScript Async / Await JavaScript Promises & Chaining Callback Function Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION
  • 3. Difference between let, var ,and constant keyword var let const It is available right from the beginning when the JavaScript was introduced It is a new way to declare variables in JavaScript, starting from ES6 or ECMAScript 2015 const is used to store a value that will not be changed throughout the execution of the script, it is also introduced with ES6 It has a global/ function scope It has block scope It also has block scope Can be updated or re- declared in its scope We can't re-declare them const represent a const value, so it can't be updated or re-declared Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION
  • 4. Destructuring array & objects The destructuring assignment is a cool feature that came along with ES6. Destructuring is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables. That is, we can extract data from arrays and objects and assign them to variables. Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION Lets understand with example Why it is important? let introduction = ["Hello", "I" , "am", "Sarah"]; let greeting = introduction[0]; let name = introduction[3]; console.log(greeting); //"Hello" console.log(name); //"Sarah" (Source : freecodecamp.org)
  • 5. Destructuring array & objects (Continue...) Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION example Why it is important? let introduction = ["Hello", "I" , "am", "Sarah"]; let [greeting, pronoun] = introduction; console.log(greeting);//"Hello" console.log(pronoun); //"I" let [greeting, pronoun] = ["Hello", "I" , "am", "Sarah"]; console.log(greeting);//"Hello" console.log(pronoun); //"I" (Source : freecodecamp.org)
  • 6. Destructuring array & objects (Continue...) Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION example Why it is important? let [greeting,,,name] = ["Hello", "I" , "am", "Sarah"]; console.log(greeting);//"Hello" console.log(name); //"Sarah" let [greeting,...intro] = ["Hello", "I" , "am", "Sarah"]; console.log(greeting);//"Hello" console.log(intro); //["I", "am", "Sarah"] (Source : freecodecamp.org)
  • 7. Destructuring array & objects (Continue...) Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION example Why it is important? function getArray() { return ["Hello", "I" , "am", "Sarah"]; } let [greeting,pronoun] = getArray(); console.log(greeting);//"Hello" console.log(pronoun);//"I" let a = 3; let b = 6; [a,b] = [b,a]; console.log(a);//6 console.log(b);//3 (Source : freecodecamp.org)
  • 8. Destructuring array & objects (Continue...) Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION let person = {name: "Sarah", country: "Nigeria", job: "Developer"}; let name = person.name; let country = person.country; let job = person.job; console.log(name);//"Sarah" console.log(country);//"Nigeria" console.log(job);//Developer" let person = {name: "Sarah", country: "Nigeria", job: "Developer"}; let {name:foo = "myName", friend: bar = "Annie"} = person; console.log(foo);//"Sarah" console.log(bar);//"Annie" (Source : freecodecamp.org)
  • 9. Destructuring array & objects (Continue...) Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION example Why it is important? let person = {name: "Sarah", country: "Nigeria", job: "Developer"}; let name, country, job; {name, country, job} = person; console.log(name); // Error : "Unexpected token =" let person = {name: "Sarah", country: "Nigeria", job: "Developer"}; let name, country, job; ({name, country, job} = person); console.log(name); //"Sarah" console.log(job); //"Developer" (Source : freecodecamp.org)
  • 10. JavaScript Hoisting Hoisting is JavaScript's default behavior of moving declarations to the top In JavaScript, a variable can be declared after it has been used. In other words; a variable can be used before it has been declared Not only variables but also function declarations are moved to the top of their scope before code execution JavaScript only hoists declarations, not initializations. Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION Example: x = 5; // Assign 5 to x elem = document.getElementById("demo"); // Find an element elem.innerHTML = x; // Display x in the element var x; // Declare x
  • 11. JavaScript Arrow Function Arrow functions were introduced in ES6. Arrow functions allow us to write shorter function syntax: Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION Before Arrow function: hello = function(){ return "Hello World!"; } After Arrow function: hello = () => { return "Hello World!"; } hello = () => "Hello World!"; hello = (val) => "Hello " + val; Arrow Functions Return Value by Default: Arrow Functions with parameters hello = val => "Hello " + val; Arrow Functions without parentheses (Source : w3schools.com)
  • 12. JavaScript Async / Await JavaScript is asynchronous, it never wait for anyone. Functions running in parallel with other functions are called asynchronous JavaScript will move on without waiting some process to finish. “async and await make promises easier to write" async makes a function return a Promise, await makes a function wait for a Promise Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION Example: async function myFunction() { return Promise.resolve("Hello"); } The keyword async before a function makes the function return a promise: (Source : w3schools.com)
  • 13. JavaScript Async / Await (Continue...) Await Syntax: The keyword await before a function makes the function wait for a promise: Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION let value = await promise The await keyword can only be used inside an async function. Example: async function myDisplay() { let myPromise = new Promise(function(myResolve, myReject) { myResolve("I love JavaScript!!"); }); document.getElementById("demo").innerHTML = await myPromise; } myDisplay(); (Source : w3schools.com)
  • 14. JavaScript Promises As we all know that JavaScript is an asynchronous scripting language. Promises are used to handle asynchronous operations in JavaScript. They are easy to manage when dealing with multiple asynchronous operations where callbacks can create callback hell leading to unmanageable code. Benefits of Promises ● Improves Code Readability ● Better handling of asynchronous operations ● Better flow of control definition in asynchronous logic ● Better Error Handling Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION
  • 15. JavaScript Promises (Continue...) A Promise has four states: ● fulfilled: Action related to the promise succeeded ● rejected: Action related to the promise failed ● pending: Promise is still pending i.e not fulfilled or rejected yet ● settled: Promise has fulfilled or rejected A promise can be created using Promise constructor. Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION Syntax: var promise = new Promise(function(resolve, reject){ //do something } );
  • 16. JavaScript Promises (Continue...) Promise Consumers: Promises can be consumed by registering functions using .then and .catch methods. then() is invoked when a promise is either resolved or rejected. Parameters: then() method takes two functions as parameters. Success or Error. Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION Example: var promise = new Promise(function(resolve, reject) { resolve('Hi its Resolved, Success'); }) promise.then( function(successMessage) { //success handler function is invoked console.log(successMessage); }, function(errorMessage) { console.log(errorMessage); }); (Source : geeksforgeeks.org)
  • 17. JavaScript Promises (Continue...) Promises Methods: Promise.all([array]) If the returned promise resolves, it is resolved with an aggregating array of the values from the resolved promises, in the same order as defined in the iterable of multiple promises. If it rejects, it is rejected with the reason from the first promise in the iterable that was rejected. Promise.allSettled() Wait until all promises have settled (each may resolve or reject). Returns a Promise that resolves after all of the given promises have either resolved or rejected, with an array of objects that each describe the outcome of each promise. Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION (Source : w3schools.com)
  • 18. JavaScript Promises (Continue...) Promises Methods: Promise.any(): Takes an iterable of Promise objects and, as soon as one of the promises in the iterable fulfills, returns a single promise that resolves with the value from that promise. Promise.finally() - finally is an instance method like then() , catch() Appends a handler to the promise, and returns a new promise that is resolved when the original promise is resolved. The handler is called when the promise is settled, whether fulfilled or rejected. Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION (Source : w3schools.com)
  • 19. JavaScript Callback Function Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION (Source : freecodecamp.org) Why do we need Callback Functions? JavaScript runs code sequentially in top-down order. However, there are some cases that code runs (or must run) after something else happens and also not sequentially. This is called asynchronous programming. Callbacks make sure that a function is not going to run before a task is completed but will run right after the task has completed. It helps us develop asynchronous JavaScript code and keeps us safe from problems and errors. In JavaScript, the way to create a callback function is to pass it as a parameter to another function, and then to call it back right after something has happened or some task is completed. Let's check an example.
  • 20. JavaScript Callback Function (Continue...) Callbacks are functions that we passed as an arguments to be invoked when the callee has finished its job Information Technology DURING TRAINING PROGRAM - WEEKLY PRESENTATION Example: function myDisplayer(some) { document.getElementById("demo").innerHTML = some; } function myCalculator(num1, num2, myCallback) { let sum = num1 + num2; myCallback(sum); } myCalculator(5, 5, myDisplayer); (Source : w3schools.com)
  • 21. Thank You. - Devang Garach devanggarach.rao@gmail.com Information Technology