SlideShare a Scribd company logo
D I N A G O L D S H T E I N
JavaScript Basics
Once Upon a Time
 Websites used to be static
 Space Jam
 HUJI
 Websites used frames
 Chiyuchon Net
 Lost-World
Behind the Scenes
 Single HTML file for each “page”
 Hard-code content into HTML
 Static navigation menus in separate frames
 Illusion of single URL using frames
And Nowadays…
 Highly interactive
 Single page applications
 Gmail
 Facebook
 Online games
 2048
 Cut the Rope
 All this thanks to JavaScript (and other stuff too )
Achieving Interactivity
 Interactivity and “navigational smoothness” are
achieved by running code on the client-side (inside
the browser)
 There used to be several client side languages, but
eventually JavaScript won the battle
 All modern browsers support JavaScript
 There are tons of third party libraries
HTML and JavaScript (and CSS)
HTML: The structure of
what’s on the screen
<ol id=“ranks”>
<li>Private</li>
<li>Corporal</li>
<li>Sergeant</li>
</ol>
CSS: Styling commands
for what’s on the screen
li { color: red }
ol { background: ... }
JS: Code that runs in the
background – the app’s
business logic
var list =
document.getElementById(
“ranks”);
var captain =
document.createElement(
“li”);
captain.innerHTML =
“Captain”;
list.appendChild(captain);
The
DOM
What Can JavaScript Do?
 Manipulate the DOM
 Create
 Remove
 Style
 Do mathematical calculations
 Store information in local storage and files
 Access the user’s location
 Draw shapes on the screen
 Fetch data from a web server
How Does it Work?
 Embed the <script></script> tag in your HTML:
 Inline
<script type=“text/javascript”>
// code goes here
</script>
 Or external (usually preferred)
<script type=“text/javascript” src=“script.js”/>
 If no configurations are present, browser executes
script as soon as it sees it before parsing the rest of
the HTML
Head or Body?
DEMO
Controlling Execution Time
 window.onload – will be executed when page has
completely loaded all content (including images,
script files, CSS files, etc.)
 document.ready – will be executed after the DOM is
ready (but might be before some content is loaded)
 Easy to use with jQuery: $(function () { ... })
 This is usually where you want to attach events, etc.
Fundamental JavaScript Concepts
var kitty = {
name: “Svetlana”,
age: 7,
purr: function () { console.log(“Purr...”); }
};
kitty.age = kitty.age + 1; // Happy birthday
kitty.purr();
var btn = document.getElementById(“myButton”);
btn.addEventListener(“click”, function () { ... });
Property
Method
Object
Event
Event
handler
Hello World (and More)
DEMO
Events and Scope
DEMO
Events and AJAX
DEMO

More Related Content

What's hot (20)

PDF
JavaScript and BOM events
Jussi Pohjolainen
 
PPT
Vanjs backbone-powerpoint
Michael Yagudaev
 
PDF
Thinkin' Tags - Rapid Prototyping of CSS Layouts
djesse
 
PPTX
HTML5 : Web to the next level
Mohamed Azouz
 
PPTX
Introduction to j_query
Basavaraj Hampali
 
PPTX
Notes on SF W3Conf
Edy Dawson
 
PPT
Introduction to j query
thewarlog
 
PDF
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Scott DeLoach
 
PPTX
Introduction to Jquery
Gurpreet singh
 
PPTX
Modern frontend
Chyngyz Arystan Uulu
 
PPTX
Single page applications mit asp.net mvc und der asp.net web api
Alexander Zeitler
 
PPTX
Building web front ends using single page applications
David Voyles
 
PDF
JavaScript para Graficos y Visualizacion de Datos
philogb
 
PPTX
Dom(document object model)
Partnered Health
 
PPTX
Intro to bootcamp
JosesGabrielLu
 
PPT
Os mobile
jimlindforpope
 
PPTX
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Endava
 
PDF
FEI 2013 - Nette framework
Adam Štipák
 
KEY
Introduction to the wonderful world of JavaScript
Jakob Torp
 
PDF
Once upon a time, there were css, js and server-side rendering
Andrea Giannantonio
 
JavaScript and BOM events
Jussi Pohjolainen
 
Vanjs backbone-powerpoint
Michael Yagudaev
 
Thinkin' Tags - Rapid Prototyping of CSS Layouts
djesse
 
HTML5 : Web to the next level
Mohamed Azouz
 
Introduction to j_query
Basavaraj Hampali
 
Notes on SF W3Conf
Edy Dawson
 
Introduction to j query
thewarlog
 
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Scott DeLoach
 
Introduction to Jquery
Gurpreet singh
 
Modern frontend
Chyngyz Arystan Uulu
 
Single page applications mit asp.net mvc und der asp.net web api
Alexander Zeitler
 
Building web front ends using single page applications
David Voyles
 
JavaScript para Graficos y Visualizacion de Datos
philogb
 
Dom(document object model)
Partnered Health
 
Intro to bootcamp
JosesGabrielLu
 
Os mobile
jimlindforpope
 
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Endava
 
FEI 2013 - Nette framework
Adam Štipák
 
Introduction to the wonderful world of JavaScript
Jakob Torp
 
Once upon a time, there were css, js and server-side rendering
Andrea Giannantonio
 

Similar to JavaScript Basics (20)

PPTX
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
PDF
WT UNIT 2 presentation :client side technologies JavaScript And Dom
SrushtiGhise
 
PPTX
01 Introduction - JavaScript Development
Tommy Vercety
 
PDF
8.-Javascript-report powerpoint presentation
JohnLagman3
 
PPTX
Javascript
Sun Technlogies
 
PDF
Introduction to jQuery
Nagaraju Sangam
 
ODP
JavaScript and jQuery Fundamentals
BG Java EE Course
 
PPT
JavaScript Missing Manual, Ch. 1
Gene Babon
 
PPT
JavaScript
Doncho Minkov
 
PPTX
Introduction to Java script for web .pptx
FahimMousa
 
PDF
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
PPT
JAVA SCRIPT
Go4Guru
 
PPT
Applied component i unit 2
Pramod Redekar
 
PPT
Easy javascript
Bui Kiet
 
PPTX
Lecture-15.pptx
vishal choudhary
 
PDF
Railsbridge javascript
p4geoff
 
PPT
INTRO TO JAVASCRIPT basic to adcance.ppt
testvarun21
 
KEY
Week 4 - jQuery + Ajax
baygross
 
PPT
jQuery with javascript training by Technnovation Labs
Prasad Shende
 
PPTX
Learning About JavaScript (…and its little buddy, JQuery!)
Julie Meloni
 
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
WT UNIT 2 presentation :client side technologies JavaScript And Dom
SrushtiGhise
 
01 Introduction - JavaScript Development
Tommy Vercety
 
8.-Javascript-report powerpoint presentation
JohnLagman3
 
Javascript
Sun Technlogies
 
Introduction to jQuery
Nagaraju Sangam
 
JavaScript and jQuery Fundamentals
BG Java EE Course
 
JavaScript Missing Manual, Ch. 1
Gene Babon
 
JavaScript
Doncho Minkov
 
Introduction to Java script for web .pptx
FahimMousa
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
JAVA SCRIPT
Go4Guru
 
Applied component i unit 2
Pramod Redekar
 
Easy javascript
Bui Kiet
 
Lecture-15.pptx
vishal choudhary
 
Railsbridge javascript
p4geoff
 
INTRO TO JAVASCRIPT basic to adcance.ppt
testvarun21
 
Week 4 - jQuery + Ajax
baygross
 
jQuery with javascript training by Technnovation Labs
Prasad Shende
 
Learning About JavaScript (…and its little buddy, JQuery!)
Julie Meloni
 
Ad

More from Dina Goldshtein (17)

PDF
How Does the Internet Work? (Wix she codes; branch)
Dina Goldshtein
 
PDF
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Dina Goldshtein
 
PDF
Look Mommy, No GC! (TechDays NL 2017)
Dina Goldshtein
 
PDF
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
Dina Goldshtein
 
PDF
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
Dina Goldshtein
 
PDF
Look Mommy, no GC! (.NET Summit 2017)
Dina Goldshtein
 
PDF
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
Dina Goldshtein
 
PDF
Look Mommy, no GC! (BrightSource)
Dina Goldshtein
 
PDF
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
Dina Goldshtein
 
PDF
Look Mommy, no GC! (SDP May 2017)
Dina Goldshtein
 
PDF
Look Mommy, No GC! (Codecamp Iasi 2017)
Dina Goldshtein
 
PDF
Look Mommy, No GC! (NDC London 2017)
Dina Goldshtein
 
PDF
How does the Internet Work?
Dina Goldshtein
 
PDF
How does the Internet Work?
Dina Goldshtein
 
PPTX
Things They Don’t Teach You @ School
Dina Goldshtein
 
PPTX
What's New in C++ 11/14?
Dina Goldshtein
 
PPTX
HTML5 Canvas
Dina Goldshtein
 
How Does the Internet Work? (Wix she codes; branch)
Dina Goldshtein
 
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Dina Goldshtein
 
Look Mommy, No GC! (TechDays NL 2017)
Dina Goldshtein
 
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
Dina Goldshtein
 
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
Dina Goldshtein
 
Look Mommy, no GC! (.NET Summit 2017)
Dina Goldshtein
 
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
Dina Goldshtein
 
Look Mommy, no GC! (BrightSource)
Dina Goldshtein
 
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
Dina Goldshtein
 
Look Mommy, no GC! (SDP May 2017)
Dina Goldshtein
 
Look Mommy, No GC! (Codecamp Iasi 2017)
Dina Goldshtein
 
Look Mommy, No GC! (NDC London 2017)
Dina Goldshtein
 
How does the Internet Work?
Dina Goldshtein
 
How does the Internet Work?
Dina Goldshtein
 
Things They Don’t Teach You @ School
Dina Goldshtein
 
What's New in C++ 11/14?
Dina Goldshtein
 
HTML5 Canvas
Dina Goldshtein
 
Ad

Recently uploaded (20)

PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Human Resources Information System (HRIS)
Amity University, Patna
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Import Data Form Excel to Tally Services
Tally xperts
 
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 

JavaScript Basics

  • 1. D I N A G O L D S H T E I N JavaScript Basics
  • 2. Once Upon a Time  Websites used to be static  Space Jam  HUJI  Websites used frames  Chiyuchon Net  Lost-World
  • 3. Behind the Scenes  Single HTML file for each “page”  Hard-code content into HTML  Static navigation menus in separate frames  Illusion of single URL using frames
  • 4. And Nowadays…  Highly interactive  Single page applications  Gmail  Facebook  Online games  2048  Cut the Rope  All this thanks to JavaScript (and other stuff too )
  • 5. Achieving Interactivity  Interactivity and “navigational smoothness” are achieved by running code on the client-side (inside the browser)  There used to be several client side languages, but eventually JavaScript won the battle  All modern browsers support JavaScript  There are tons of third party libraries
  • 6. HTML and JavaScript (and CSS) HTML: The structure of what’s on the screen <ol id=“ranks”> <li>Private</li> <li>Corporal</li> <li>Sergeant</li> </ol> CSS: Styling commands for what’s on the screen li { color: red } ol { background: ... } JS: Code that runs in the background – the app’s business logic var list = document.getElementById( “ranks”); var captain = document.createElement( “li”); captain.innerHTML = “Captain”; list.appendChild(captain); The DOM
  • 7. What Can JavaScript Do?  Manipulate the DOM  Create  Remove  Style  Do mathematical calculations  Store information in local storage and files  Access the user’s location  Draw shapes on the screen  Fetch data from a web server
  • 8. How Does it Work?  Embed the <script></script> tag in your HTML:  Inline <script type=“text/javascript”> // code goes here </script>  Or external (usually preferred) <script type=“text/javascript” src=“script.js”/>  If no configurations are present, browser executes script as soon as it sees it before parsing the rest of the HTML
  • 10. Controlling Execution Time  window.onload – will be executed when page has completely loaded all content (including images, script files, CSS files, etc.)  document.ready – will be executed after the DOM is ready (but might be before some content is loaded)  Easy to use with jQuery: $(function () { ... })  This is usually where you want to attach events, etc.
  • 11. Fundamental JavaScript Concepts var kitty = { name: “Svetlana”, age: 7, purr: function () { console.log(“Purr...”); } }; kitty.age = kitty.age + 1; // Happy birthday kitty.purr(); var btn = document.getElementById(“myButton”); btn.addEventListener(“click”, function () { ... }); Property Method Object Event Event handler
  • 12. Hello World (and More) DEMO

Editor's Notes

  • #6: כל האינטראקטיביות הזאת מושגת תודות לג׳אווה סקריפט, וכמובן תמיכה מהדפדפנים ואנשים שכתבו ספריות וכו׳ וכו׳. אבל בבסיס של כל זה עומדת היכולת לכתוב קוד שרץ בצד המשתמש וזה נעשה בימינו באמצעות ג׳אווה סקריפט. אני לא אכנס לפרטי ההיסטוריה, אני גם לא כל כך מתמצאת אבל רק אציין כעת שפעם היו עוד שפות שניתן היה לכתוב איתן קוד שירוץ בדפדפן אבל בסופו של דבר ג׳אווה סקריפט נצחה והיא השפה השלטת היום. למעשה, אם תחפשו באינטרנט את שפת התכנות הפופולרית ביותר תגלו ש(נכון ל-2013) היא השפה הרביעית בפופולריות (http://langpop.com/). יש להם שיטה שבה הם מודדים פופולריות אבל זה לא כל כך קשור לנושא. הפואנטה היא שזו שפה מאוד פופולרית ויש בוכטה קוד שכתובה בה. כל הדפדפנים המודרניים תומכים בג׳אווה סקריפט, יש המון ספריות חיצוניות, המון חומרי קריאה גם באינטרנט וגם מודפסים, המון שאלות ב-stack overflow ובכלל המון תמיכה מקוונת.
  • #7: אנחנו ממש מתקרבים לת׳כלס. לפני שממש נתחיל לכתוב קוד צריך להסביר רק עוד שני דברים קצרים על האנטומיה של דף ווב. אפשר לומר שבגדול דף ווב מורכב משלושה חלקים עיקריים: 1. ה-HTML שמגדיר איך הדף נראה. הוא אומר איפה יש כותרות ומה כתוב בהן, איפה יש רשימות, איפה יש כפתורים ואיפה יש תמונות. ה-HTML כתוב בצורה היררכית שדומה מאוד ל-XML ובכך יוצרת גרף של כל האלמנטים שבעמוד. הגרף הזה נקרא (DOM (Document object model. כשדפדפן מקבל דף הוא יודע לפרסר את ה-DOM ולהבין ממנו איך צריך להציג את העמוד. 2. ה-CSS שקשור גם הוא באופן ישיר לתצוגה. הוא לא קובע מהם האלמנטים שנמצאים על הדף אבל הוא יכול לקבוע את כל הפרמטרים התצוגתיים שלהם. למשל, ניתן לקבוע שכל הכתפורים הם בצבע אדום ושכל האלמנטים של הרשימות יש להם רקע צהוב. ניתן לקבוע את המאפיינים האלה גם דרך ה-HTML אך נהוג לשמור ב-HTML רק את האלמנטים ואילו את ההגדרות של הצבעים וכו׳ לשמור ב-CSS. ככה זה מפריד את תחומי האחריות ומאפשר גם לחלוק את אותו העיצוב בין עמודים שונים. 3. הקוד שרץ הרקע בזמן שהעמוד מוצג. וזה מה שאנחנו נמתמקד בו בזמן שנותר.
  • #8: מה אנחנו יכולים לעשות בקוד? ובכל, הכל. אנחנו יכולים להתעסק עם ה-DOM – כלומר ליצור, להוריד, לשנות, לעצב אלמנטים, אפילו אם הם לא היו קיימים ב-HTML או ב-CSS המקוריים. אנחנו יכולים לעשות פעולות מתמטיות כמו חיבור, כפל, חילוק וכו׳. אנחנו יכולים לשמור מידע במיקום לוקאלי כדי שנוכל להמשיך לפעול ללא חיבור לאינטרנט. אנחנו יכולים לקבל מהמשתמש נתונים כמו טקסט, מספרים או קבצים ולעבד את הנתונים האלה או לשלוח אותם לשרת מרוחק. אנחנו יכולים לקבל את המיקום של המשתמש כדי שנוכל למשל לשנות את שפת האתר לפי המיקום או לעשות redirect לגרסה לוקאלית עם פרטים רלוונטיים למיקום. אנחנו יכולים לצייר צורות, תמונות, סרטים על המסך או להשמיע מוסיקה. אנחנו יכולים להביא מידע משרת אחר. ועוד ועוד.
  • #9: מה קורה מאחורי הקלעים? הדפדפנים תומכים באלמנט מיוחד מסוג script. האלמנט הזה יכול ממש להכיל בתוכו את הקוד או להפנות לקובץ חיצוני שמכיל את הקוד. זו כמובן האפשרות המועדפת משום שזה שומר לנו על סדר וניתן לתחזק את הקוד בנפרד מהתצוגה. גם יש סיכוי סביר שאנשים שונים עובדים על שני החלקים האלה. כאשר הדפדפן טוען את הדף, כמו שאמרנו קודם, הוא מפרסר את ה-DOM. אם אין קונפיגורציות מיוחדות (שלא נדבר עליהן כאן) אז ברגע שהוא נתקל באלמנט הסקריפט הוא לוקח את הקוד ומתחיל להרציץ אותן. עד שהוא לא מסיים להריץ הוא לא ממשיך לפרסר את שאר האלמנטים.
  • #10: לדף HTML יש שני חלקים – הראש והגוף. הראש מופיע לפני הגוף ואפשר לשים בו כל מיני דברים או למשל הפניה לסקריפטים או ל-CSS-ים ואילו בגוף כותבים ממש את תוכן העמוד. את הסקריפטים נהוג לשים באחד מהקצוות של הדף – או בראש או בתחתית הגוף. האם זה משנה? כאן אנחנו נתקלים לראשונה ב-JSFIDDLE. זה אתר שמאפשר בקלות לכתוב דף ווב עם תצוגה וקוד והכל ולהריץ אותו. יש לו שלושה חלונות לעריכה של האתר וחלון אחד של תצוגה. יש לו גם אופציה להוסיף ספריות סטנדרטיות אבל אנחנו לא נשתמש בזה עכשיו ונכתוב קוד ג׳אווה סקריפט טהור. חוץ מזה, מה שנחמד באתר הוא שהוא פוטר אותנו מהתעסקות עם כל מיני דברים טכניים שצריך לכתוב כדי לבנות אתר. ב-HTML רגיל יש כל מיני מעטפות שצריך לכתוב אבל האתר הזה עושה את זה בשבילנו. למה הקוד עובד כשהוא מופיע בגוף ולא בראש? ובכן, כפי שאמרנו, הקוד רץ מיד כשהדפדפן פוגש את האלמנט. אם הדפדפן פוגש את האלמנט לפני ששאר האלמנטים מוגדרים אז הקוד פשוט לא מצליח לעשות כלום...