SlideShare a Scribd company logo
1 of 36
Loops, Arrays, Functions,
Strings, Objects, Variables
Scope & Events
Loops, Arrays, Functions, Objects...
Table of Contents
Loops in JavaScript
while, do-while, for, for-in
Arrays in JavaScript
Declaring and Creating Arrays
Accessing and Processing Array Elements
Strings in JavaScript
Processing, Trimming, Concatenating
Loops
Types of Loops in JS
Types of loops in JS
while(…) loop
do { … } while (…) loop
for loop
for-in loop
Infinite loops – a loop that never ends
Nested loops – a composition of loops
How To Use While Loop?
The simplest and most frequently used loop!
The repeat condition (loop condition)
The condition is evaluated to true or false
0, "", null are evaluated as false
while (condition) {
statements;
}
Using Do-While Loop
Another classical loop structure is:
The block of statements is repeated
While the boolean loop condition holds
The loop is executed at least once
do {
statements;
} while (condition);
For Loop – Definition
Initialization – executed once, just before the loop is entered
Test – checked before each iteration of the loop (loop condition)
Update – executed at each iteration after the loop body
Body – the code that will be executed at each iteration
for (var number = 0; number < 10; number++) {
// Can use number here
}
// number is still usable here
Using break Operator
The break operator exits the inner-most loop
The break operator is used to stop the loop’s iteration.
It is not necessary to use it
While (condition){
if(another condition){
break;
}
}
for-in Loop
Iterating over the Properties of an Object
The objects has some properties, to in order to access
them and iterate them you can use for-in loop.
The for-in loop can be replaced with for loop, but both
have odds pros and cons.
What is for-in Loop?
for-in loop iterates over the properties of an object
For arrays / strings iterates over their indices (0…length-1)
For any other object, for-in iterates over its properties
Iterating over the elements of an array / string:
var arr = [10, 20, 30, 40, 50];
for (var index in arr) { console.log(arr[index]) }
// 10, 20, 30, 40, 50
var str = "welcome";
for (var index in str) { console.log(str[index]) }
// w, e, l, c, o, m, e
For-in Loop
Iterating over the properties of an object:
Typical mistake is to use the
key instead of the value:
var obj = { name: 'Steve', age: 23, location: 'Sofia' };
for (var key in obj) { console.log(obj[key]); }
// Steve, 23 , Sofia
var obj = { name: 'Steve', age: 23, location: 'Sofia' };
for (var key in obj) { console.log(key); }
// name, age, location
var arr = [10, 20, 30, 40, 50];
for (var i in arr) { console.log(i); }
// 0, 1, 2, 3, 4
for-in loop - Live Demo
Arrays
What are Arrays?
An array is an ordered sequence of elements
The order of the elements is fixed
Can get the current length (Array.length)
In JS arrays can change their size at runtime (add / delete)
Creating Arrays
Creating Arrays in JavaScript
// Array holding integers
var numbers = [1, 2, 3, 4, 5];
// Array holding strings
var weekDays = ['Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday', 'Sunday'];
// Array of mixed data
var mixedArr = [1, new Date(), 'hello'];
// Array of arrays (matrix)
var matrix = [
['0,0', '0,1', '0,2'],
['1,0', '1,1', '1,2'],
['2,0', '2,1', '2,2']];
Declare and Initialize Arrays
Initializing an array in JavaScript can be done in several ways:
Using new Array(elements):
Using new Array(initialLength):
var arr = new Array(1, 2, 3, 4, 5); // [1, 2, 3, 4, 5]
var arr = new Array(10); // [undefined × 10]
Using new Array():
Using array literal (recommended):
Declare and Initialize Arrays
var arr = new Array(); // []
var arr = [1, 2, 3, 4, 5]; // [1, 2, 3, 4, 5]
Manipulating arrays
Push
Pup
Shift
Unshift
Accessing Array Elements - Live Demo
Read and Modify Elements by Index:
Objects
How to define objects
Shorthand syntax
Objects have properties
Defining object properties
Alternative syntax
Variable property name
Objects have methods
Defining methods
Using methods
Methods are simply callable properties.
Properties can be assigned and accessed dynamically.
Objects, properties and methods
(almost) Everything is an object
Array, Json object, string literal
Primitive values become Objects
Due to type coercion
Using object constructors
Built-in object constructors
Constructor functions
Extending objects
Prototypal inheritance
Summary
Objects
Properties
Methods
Constructors
Extending
Functions
Functions are callable
objects
Javascript scope
Inner scope vs outer scope
Global scope
Global variables can be
used everywhere
In HTML, global scope is
the window object
All global variables belong to the
window object.
More global scope
Global variables:
Defined outside of any function
Properties to the global object
Not declared with “var” operator
Binding of this
Inside a function call,
“this” is bound to the global
object.
Inside a call for with “new”
operator, “this” is bound to
the returned object.
Controlling this binding
Using function methods apply, call, bind.
DOM events
Events can target DOM elements.
Can also be used from event attributes.
Why is the first event listener needed?

More Related Content

What's hot

JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APItvaleev
 
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
Scala for Java programmers
Scala for Java programmersScala for Java programmers
Scala for Java programmers輝 子安
 
Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?evenellie
 
Turtle Graphics in Groovy
Turtle Graphics in GroovyTurtle Graphics in Groovy
Turtle Graphics in GroovyJim Driscoll
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIITakuma Watabiki
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsAndrei Pangin
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMsunng87
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019Leonardo Borges
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorialnikomatsakis
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
 
Hello, Guava !
Hello, Guava !Hello, Guava !
Hello, Guava !輝 子安
 

What's hot (20)

JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream API
 
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
Scala for Java programmers
Scala for Java programmersScala for Java programmers
Scala for Java programmers
 
Pg py-and-squid-pypgday
Pg py-and-squid-pypgdayPg py-and-squid-pypgday
Pg py-and-squid-pypgday
 
Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?
 
Spockを使おう!
Spockを使おう!Spockを使おう!
Spockを使おう!
 
Turtle Graphics in Groovy
Turtle Graphics in GroovyTurtle Graphics in Groovy
Turtle Graphics in Groovy
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIII
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap Dumps
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
 
Hello, Guava !
Hello, Guava !Hello, Guava !
Hello, Guava !
 

Viewers also liked

FFW Gabrovo PMG - Development Process
FFW Gabrovo PMG - Development ProcessFFW Gabrovo PMG - Development Process
FFW Gabrovo PMG - Development ProcessToni Kolev
 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1Toni Kolev
 
Brexit
BrexitBrexit
Brexitrven14
 
FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryFFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryToni Kolev
 
FFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSFFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSToni Kolev
 
Brexit
BrexitBrexit
Brexitrven14
 
FFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTMLFFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTMLToni Kolev
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3Toni Kolev
 
Trading Floor - Алексей Марков восхождение
Trading Floor - Алексей Марков восхождение Trading Floor - Алексей Марков восхождение
Trading Floor - Алексей Марков восхождение rven14
 

Viewers also liked (9)

FFW Gabrovo PMG - Development Process
FFW Gabrovo PMG - Development ProcessFFW Gabrovo PMG - Development Process
FFW Gabrovo PMG - Development Process
 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1
 
Brexit
BrexitBrexit
Brexit
 
FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryFFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQuery
 
FFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSFFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSS
 
Brexit
BrexitBrexit
Brexit
 
FFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTMLFFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTML
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
Trading Floor - Алексей Марков восхождение
Trading Floor - Алексей Марков восхождение Trading Floor - Алексей Марков восхождение
Trading Floor - Алексей Марков восхождение
 

Similar to FFW Gabrovo PMG - JavaScript 2

Core java concepts
Core    java  conceptsCore    java  concepts
Core java conceptsChikugehlot
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................suchitrapoojari984
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascriptMD Sayem Ahmed
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.jstimourian
 
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
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Manoj Ellappan
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Conceptsmdfkhan625
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 

Similar to FFW Gabrovo PMG - JavaScript 2 (20)

ES6 and BEYOND
ES6 and BEYONDES6 and BEYOND
ES6 and BEYOND
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
 
8558537werr.pptx
8558537werr.pptx8558537werr.pptx
8558537werr.pptx
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Scala
ScalaScala
Scala
 

Recently uploaded

Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 

FFW Gabrovo PMG - JavaScript 2

  • 1. Loops, Arrays, Functions, Strings, Objects, Variables Scope & Events Loops, Arrays, Functions, Objects...
  • 2. Table of Contents Loops in JavaScript while, do-while, for, for-in Arrays in JavaScript Declaring and Creating Arrays Accessing and Processing Array Elements Strings in JavaScript Processing, Trimming, Concatenating
  • 4. Types of Loops in JS Types of loops in JS while(…) loop do { … } while (…) loop for loop for-in loop Infinite loops – a loop that never ends Nested loops – a composition of loops
  • 5. How To Use While Loop? The simplest and most frequently used loop! The repeat condition (loop condition) The condition is evaluated to true or false 0, "", null are evaluated as false while (condition) { statements; }
  • 6. Using Do-While Loop Another classical loop structure is: The block of statements is repeated While the boolean loop condition holds The loop is executed at least once do { statements; } while (condition);
  • 7. For Loop – Definition Initialization – executed once, just before the loop is entered Test – checked before each iteration of the loop (loop condition) Update – executed at each iteration after the loop body Body – the code that will be executed at each iteration for (var number = 0; number < 10; number++) { // Can use number here } // number is still usable here
  • 8. Using break Operator The break operator exits the inner-most loop The break operator is used to stop the loop’s iteration. It is not necessary to use it While (condition){ if(another condition){ break; } }
  • 9. for-in Loop Iterating over the Properties of an Object The objects has some properties, to in order to access them and iterate them you can use for-in loop. The for-in loop can be replaced with for loop, but both have odds pros and cons.
  • 10. What is for-in Loop? for-in loop iterates over the properties of an object For arrays / strings iterates over their indices (0…length-1) For any other object, for-in iterates over its properties Iterating over the elements of an array / string: var arr = [10, 20, 30, 40, 50]; for (var index in arr) { console.log(arr[index]) } // 10, 20, 30, 40, 50 var str = "welcome"; for (var index in str) { console.log(str[index]) } // w, e, l, c, o, m, e
  • 11. For-in Loop Iterating over the properties of an object: Typical mistake is to use the key instead of the value: var obj = { name: 'Steve', age: 23, location: 'Sofia' }; for (var key in obj) { console.log(obj[key]); } // Steve, 23 , Sofia var obj = { name: 'Steve', age: 23, location: 'Sofia' }; for (var key in obj) { console.log(key); } // name, age, location var arr = [10, 20, 30, 40, 50]; for (var i in arr) { console.log(i); } // 0, 1, 2, 3, 4
  • 12. for-in loop - Live Demo
  • 14. What are Arrays? An array is an ordered sequence of elements The order of the elements is fixed Can get the current length (Array.length) In JS arrays can change their size at runtime (add / delete)
  • 16. Creating Arrays in JavaScript // Array holding integers var numbers = [1, 2, 3, 4, 5]; // Array holding strings var weekDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; // Array of mixed data var mixedArr = [1, new Date(), 'hello']; // Array of arrays (matrix) var matrix = [ ['0,0', '0,1', '0,2'], ['1,0', '1,1', '1,2'], ['2,0', '2,1', '2,2']];
  • 17. Declare and Initialize Arrays Initializing an array in JavaScript can be done in several ways: Using new Array(elements): Using new Array(initialLength): var arr = new Array(1, 2, 3, 4, 5); // [1, 2, 3, 4, 5] var arr = new Array(10); // [undefined × 10]
  • 18. Using new Array(): Using array literal (recommended): Declare and Initialize Arrays var arr = new Array(); // [] var arr = [1, 2, 3, 4, 5]; // [1, 2, 3, 4, 5]
  • 20. Accessing Array Elements - Live Demo Read and Modify Elements by Index:
  • 21. Objects How to define objects Shorthand syntax
  • 22. Objects have properties Defining object properties Alternative syntax Variable property name
  • 23. Objects have methods Defining methods Using methods
  • 24. Methods are simply callable properties. Properties can be assigned and accessed dynamically. Objects, properties and methods
  • 25. (almost) Everything is an object Array, Json object, string literal Primitive values become Objects Due to type coercion
  • 26. Using object constructors Built-in object constructors Constructor functions
  • 31. Inner scope vs outer scope
  • 32. Global scope Global variables can be used everywhere In HTML, global scope is the window object All global variables belong to the window object.
  • 33. More global scope Global variables: Defined outside of any function Properties to the global object Not declared with “var” operator
  • 34. Binding of this Inside a function call, “this” is bound to the global object. Inside a call for with “new” operator, “this” is bound to the returned object.
  • 35. Controlling this binding Using function methods apply, call, bind.
  • 36. DOM events Events can target DOM elements. Can also be used from event attributes. Why is the first event listener needed?