SlideShare a Scribd company logo
1 of 9
Download to read offline
Declarations with let
Level 1 – Section 1
Forum Web App
Together, we'll build features
that are part of a web forum!
Loading Profiles
The loadProfiles function takes an array of users and adds their profile to the sidebar.
displays active
users for this topic
<!DOCTYPE html>
//...
<script src="./load-profiles.js">
<script>
loadProfiles(["Sam", "Tyler", "Brook"]);
</script>
</body>
</html>
The loadProfiles Function
Might take a while to process, 

so a loading message is displayed
Shouldn't take that long, so 

we display a different message
This function displays a different message according to the number of arguments.
//... fetch names and build sidebar
}.
}
function loadProfiles(userNames){
if(userNames.length > 3){
loadingMessage = "This might take a while...";var
_displaySpinner(loadingMessage);
}else{
var flashMessage = "Loading Profiles";
_displayFlash(flashMessage);
}/
How loadProfiles Is Executed
loadProfiles(["Sam", "Tyler", "Brook", "Alex"]);
The else block is not executed
2. The loadingMessage variable
is declared and assigned a value
3. The displaySpinner function is called
1. Executes the if block
//...
}.
}
function loadProfiles(userNames){
if(userNames.length > 3){
loadingMessage = "This might take a while...";var
_displaySpinner(loadingMessage);
} else
var flashMessage
_
}
Unexpected Behavior With var
console.log(flashMessage);
console.log(flashMessage);
}.
}
Why no ReferenceError ?
flashMessage is never declared...
...but outputs undefined and does not generate error (?!)
undefined>
undefined>
This indicates a 

console output
function loadProfiles(userNames){
if(userNames.length > 3){
loadingMessage = "This might take a while...";var
_displaySpinner(loadingMessage);
else
var flashMessage
_
}
Understanding Hoisting
Automatically moved here 

by the JavaScript runtime
Prior to executing our code, JavaScript moves var declarations all the way up to the top 

of the scope. This is known as hoisting.
function loadProfiles(userNames){
if(userNames.length > 3){
loadingMessage = "This might take a while...";
flashMessage = "Loading Profiles";
var
var
var loadingMessage, flashMessage;
_displaySpinner(loadingMessage);
_displayFlash(flashMessage);
}/
//....
}.
}else{
Declaring Variables With let
let variables are scoped to the nearest block and are NOT hoisted.
Not visible outside else block
Not visible outside if block
(A block is any code section within curly braces, like if, else, for, while, etc.)
function loadProfiles(userNames){
let
if(userNames.length > 3){
loadingMessage = "This might take a while...";
let flashMessage = "Loading Profiles";
_displaySpinner(loadingMessage);
}.
_displayFlash(flashMessage);
}/
//....
}else{
Expected Behavior With let
Using let, variables are “trapped” inside their respective if and else blocks.
loadProfiles(["Sam", "Tyler", "Brook", "Alex"]);
Expected behavior, similar to

other programming languages!
ReferenceError: flashMessage is not defined>
ReferenceError: flashMessage is not defined>
function loadProfiles(userNames){
if(userNames.length > 3){
let loadingMessage = "This might take a while...";
console.log(flashMessage);
console.log(flashMessage);
_displaySpinner(loadingMessage);
let flashMessage = "Loading Profiles";
_displayFlash(flashMessage);
}/
}.
}else{

More Related Content

What's hot (9)

Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in mule
 
Activemq installation and master slave setup using shared broker data
Activemq installation and master slave setup using shared broker dataActivemq installation and master slave setup using shared broker data
Activemq installation and master slave setup using shared broker data
 
Encrypting/Decrypting mule
Encrypting/Decrypting  muleEncrypting/Decrypting  mule
Encrypting/Decrypting mule
 
Mapping and listing in mule
Mapping and listing in muleMapping and listing in mule
Mapping and listing in mule
 
Map in Mule
Map in MuleMap in Mule
Map in Mule
 
Groovy in Mule
Groovy in MuleGroovy in Mule
Groovy in Mule
 
Mule quartz
Mule quartz Mule quartz
Mule quartz
 
Mule message enricher
Mule message enricherMule message enricher
Mule message enricher
 
Mule soap
Mule soapMule soap
Mule soap
 

Similar to testing1

Cliw - extension development
Cliw -  extension developmentCliw -  extension development
Cliw - extension developmentvicccuu
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkIndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Frameworkvhazrati
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Lookrumsan
 
New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectorsrtretola
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScriptAmitai Barnea
 

Similar to testing1 (20)

Cliw - extension development
Cliw -  extension developmentCliw -  extension development
Cliw - extension development
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
backend
backendbackend
backend
 
backend
backendbackend
backend
 
Loadrunner
LoadrunnerLoadrunner
Loadrunner
 
Soap Component
Soap ComponentSoap Component
Soap Component
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Web 4 | Core JavaScript
Web 4 | Core JavaScriptWeb 4 | Core JavaScript
Web 4 | Core JavaScript
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectors
 
Html web workers
Html web workersHtml web workers
Html web workers
 
How to use soap component
How to use soap componentHow to use soap component
How to use soap component
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
 

Recently uploaded

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Recently uploaded (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

testing1

  • 1. Declarations with let Level 1 – Section 1
  • 2. Forum Web App Together, we'll build features that are part of a web forum!
  • 3. Loading Profiles The loadProfiles function takes an array of users and adds their profile to the sidebar. displays active users for this topic <!DOCTYPE html> //... <script src="./load-profiles.js"> <script> loadProfiles(["Sam", "Tyler", "Brook"]); </script> </body> </html>
  • 4. The loadProfiles Function Might take a while to process, 
 so a loading message is displayed Shouldn't take that long, so 
 we display a different message This function displays a different message according to the number of arguments. //... fetch names and build sidebar }. } function loadProfiles(userNames){ if(userNames.length > 3){ loadingMessage = "This might take a while...";var _displaySpinner(loadingMessage); }else{ var flashMessage = "Loading Profiles"; _displayFlash(flashMessage); }/
  • 5. How loadProfiles Is Executed loadProfiles(["Sam", "Tyler", "Brook", "Alex"]); The else block is not executed 2. The loadingMessage variable is declared and assigned a value 3. The displaySpinner function is called 1. Executes the if block //... }. } function loadProfiles(userNames){ if(userNames.length > 3){ loadingMessage = "This might take a while...";var _displaySpinner(loadingMessage); } else var flashMessage _ }
  • 6. Unexpected Behavior With var console.log(flashMessage); console.log(flashMessage); }. } Why no ReferenceError ? flashMessage is never declared... ...but outputs undefined and does not generate error (?!) undefined> undefined> This indicates a 
 console output function loadProfiles(userNames){ if(userNames.length > 3){ loadingMessage = "This might take a while...";var _displaySpinner(loadingMessage); else var flashMessage _ }
  • 7. Understanding Hoisting Automatically moved here 
 by the JavaScript runtime Prior to executing our code, JavaScript moves var declarations all the way up to the top 
 of the scope. This is known as hoisting. function loadProfiles(userNames){ if(userNames.length > 3){ loadingMessage = "This might take a while..."; flashMessage = "Loading Profiles"; var var var loadingMessage, flashMessage; _displaySpinner(loadingMessage); _displayFlash(flashMessage); }/ //.... }. }else{
  • 8. Declaring Variables With let let variables are scoped to the nearest block and are NOT hoisted. Not visible outside else block Not visible outside if block (A block is any code section within curly braces, like if, else, for, while, etc.) function loadProfiles(userNames){ let if(userNames.length > 3){ loadingMessage = "This might take a while..."; let flashMessage = "Loading Profiles"; _displaySpinner(loadingMessage); }. _displayFlash(flashMessage); }/ //.... }else{
  • 9. Expected Behavior With let Using let, variables are “trapped” inside their respective if and else blocks. loadProfiles(["Sam", "Tyler", "Brook", "Alex"]); Expected behavior, similar to
 other programming languages! ReferenceError: flashMessage is not defined> ReferenceError: flashMessage is not defined> function loadProfiles(userNames){ if(userNames.length > 3){ let loadingMessage = "This might take a while..."; console.log(flashMessage); console.log(flashMessage); _displaySpinner(loadingMessage); let flashMessage = "Loading Profiles"; _displayFlash(flashMessage); }/ }. }else{