SlideShare une entreprise Scribd logo
1  sur  14
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

Contenu connexe

Tendances

Thinkin' Tags - Rapid Prototyping of CSS Layouts
Thinkin' Tags - Rapid Prototyping of CSS LayoutsThinkin' Tags - Rapid Prototyping of CSS Layouts
Thinkin' Tags - Rapid Prototyping of CSS Layoutsdjesse
 
HTML5 : Web to the next level
HTML5 : Web to the next levelHTML5 : Web to the next level
HTML5 : Web to the next levelMohamed Azouz
 
Notes on SF W3Conf
Notes on SF W3ConfNotes on SF W3Conf
Notes on SF W3ConfEdy Dawson
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j querythewarlog
 
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStartBest Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStartScott DeLoach
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to JqueryGurpreet singh
 
Single page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiSingle page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiAlexander Zeitler
 
Building web front ends using single page applications
Building web front ends using single page applicationsBuilding web front ends using single page applications
Building web front ends using single page applicationsDavid Voyles
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datosphilogb
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)Partnered Health
 
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014Endava
 
FEI 2013 - Nette framework
FEI 2013 - Nette frameworkFEI 2013 - Nette framework
FEI 2013 - Nette frameworkAdam Štipák
 
Introduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScriptIntroduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScriptJakob Torp
 
Once upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side renderingOnce upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side renderingAndrea Giannantonio
 

Tendances (20)

JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
Vanjs backbone-powerpoint
Vanjs backbone-powerpointVanjs backbone-powerpoint
Vanjs backbone-powerpoint
 
Thinkin' Tags - Rapid Prototyping of CSS Layouts
Thinkin' Tags - Rapid Prototyping of CSS LayoutsThinkin' Tags - Rapid Prototyping of CSS Layouts
Thinkin' Tags - Rapid Prototyping of CSS Layouts
 
HTML5 : Web to the next level
HTML5 : Web to the next levelHTML5 : Web to the next level
HTML5 : Web to the next level
 
Introduction to j_query
Introduction to j_queryIntroduction to j_query
Introduction to j_query
 
Notes on SF W3Conf
Notes on SF W3ConfNotes on SF W3Conf
Notes on SF W3Conf
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j query
 
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStartBest Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
Modern frontend
Modern frontendModern frontend
Modern frontend
 
Single page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiSingle page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web api
 
Building web front ends using single page applications
Building web front ends using single page applicationsBuilding web front ends using single page applications
Building web front ends using single page applications
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Intro to bootcamp
Intro to bootcampIntro to bootcamp
Intro to bootcamp
 
Os mobile
Os mobileOs mobile
Os mobile
 
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
 
FEI 2013 - Nette framework
FEI 2013 - Nette frameworkFEI 2013 - Nette framework
FEI 2013 - Nette framework
 
Introduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScriptIntroduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScript
 
Once upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side renderingOnce upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side rendering
 

Similaire à JavaScript Basics

01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript DevelopmentTommy Vercety
 
Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterIvo Andreev
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application developmentzonathen
 
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...Frédéric Harper
 
Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Sho Ito
 
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsBusy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsJAX London
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Doris Chen
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizationsChris Love
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Webnewcircle
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQueryAnil Kumar
 
The Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devicesThe Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devicesWesley Hales
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsMark Rackley
 
Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX DesignersAshlimarie
 

Similaire à JavaScript Basics (20)

01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
 
Html5 & less css
Html5 & less cssHtml5 & less css
Html5 & less css
 
Html5
Html5Html5
Html5
 
Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform better
 
Html5
Html5Html5
Html5
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...
 
Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~
 
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsBusy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Edge of the Web
Edge of the WebEdge of the Web
Edge of the Web
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
 
Html 5 - What's new?
Html 5 - What's new?Html 5 - What's new?
Html 5 - What's new?
 
Decoding the Web
Decoding the WebDecoding the Web
Decoding the Web
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQuery
 
The Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devicesThe Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devices
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
 
Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX Designers
 

Plus de Dina Goldshtein

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

Plus de Dina Goldshtein (17)

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

Dernier

how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfmetbey
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Maxim Salnikov
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfkalichargn70th171
 
What is a Recruitment Management Software?
What is a Recruitment Management Software?What is a Recruitment Management Software?
What is a Recruitment Management Software?NYGGS Automation Suite
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypseTomasz Kowalczewski
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIInflectra
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In sowetokasambamuno
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024SimonedeGijt
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Henry Schreiner
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14VMware Tanzu
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksJinanKordab
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Lisi Hocke
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Chirag Panchal
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Andrea Goulet
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletAndrea Goulet
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In hararekasambamuno
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringPrakhyath Rai
 

Dernier (20)

Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
What is a Recruitment Management Software?
What is a Recruitment Management Software?What is a Recruitment Management Software?
What is a Recruitment Management Software?
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 

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

Notes de l'éditeur

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