SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Introduction to JavaScript
Hands-on
Getting Started with JavaScript
Kevin Hoyt and Mihai Corlan | Adobe
About Us
Kevin Hoyt
@krhoyt
Adobe Evangelist
Mihai Corlan
@mcorlan
Adobe Evangelist
What is JavaScript
1. Prototype-based
2. Scripting language
3. Dynamic
4. Weakly typed
5. First-class functions
6. Multi-paradigm
@krhoyt @mcorlan
Adding JavaScript to a Page - Inline
<script type="text/javascript">
document.writeln( "It works!" );
</script>
@krhoyt @mcorlan
Adding JavaScript to a Page - External
<script
src="myscript.js"
type="text/javascript">
</script>
document.writeln( "It works!" );
In your HTML file:
In the "myscript.js" file:
@krhoyt @mcorlan
Variables
var _myName = "Mihai";
var hisName = "Kevin";
Variables are defined using the special keyword "var"
followed by a valid name. Valid names can be any
combination of letters, "$" and "_".
@krhoyt @mcorlan
Variable Types
var myVar; // undefined
var myVar = null; // null
var myVar = 3.14; // Number
var myVar = "MAX"; // String
var myVar = true; // Boolean
var myVar = { // Object
first: "Mihai",
last: "Corlan"
};
@krhoyt @mcorlan
Arrays
var simpleArray = [1, 2, 3, 4];
var complexArray = new Array();
complexArray.push( 1 );
complexArray.push( "Kevin" );
An array is an ordered list of variables. Values inside
the array can be of any type. You can even mix the
types for each value.
@krhoyt @mcorlan
Custom Data Types
An object is a collection of properties assigned to a
single variable.
var myVar = {
index: 0,
name: "Mihai Corlan",
isAdobe: true
};
@krhoyt @mcorlan
Control Structures - if ... else
var color = "red";
if( color === "red" ) // === vs. ==
{
document.body.style.backgroundColor = "red";
} else if( color === "blue" ) {
document.body.style.backgroundColor = "blue";
} else {
document.body.style.backgroundColor = "#CCFFFF";
}
@krhoyt @mcorlan
Control Structures - switch ... case
var color = "red";
switch( color ) {
case "red":
document.writeln( "It is red." );
break;
case "blue":
document.writeln( "It is blue." );
break;
default:
document.writeln( "Huh?" );
break;
}
@krhoyt @mcorlan
Control Structures - for
var div;
var numbers = [1, 2, 3, 4, 5, 6];
for( var n = 0; n < numbers.length; n++ )
{
div = document.createElement( "div" );
div.innerHTML = numbers[n];
div.style.fontSize = numbers[n] + "em";
document.body.appendChild( div );
}
@krhoyt @mcorlan
Control Structures - while
var current = 0;
var limit = 5;
while( current < limit )
{
document.writeln( current );
current = current + 1;
}
@krhoyt @mcorlan
Control Structures - do ... while
var current = 0;
var limit = 5;
do {
document.writeln( current );
current = current + 1;
} while( current < limit );
@krhoyt @mcorlan
Functions
function sayHello()
{
document.writeln( "Hello World!" );
}
sayHello();
A function is a block of code that will be executed
when it is called. Functions allow you to reuse code
that needs to be executed more than once, or in more
than one place.
@krhoyt @mcorlan
Functions - Arguments and Return Values
function addNumbers( value1, value2 )
{
return value1 + value2;
}
var sum = addNumbers( 2, 2 );
document.writeln( sum );
@krhoyt @mcorlan
Variable Scope
var value = 0;
function tellMe() {
var value = 1;
document.writeln( value );
}
tellMe(); // Will be 1
document.writeln( value ); // Will be 0
JavaScript has one "global" scope. Each function
also has its own scope. If you omit "var" then values
default to the global scope.
@krhoyt @mcorlan
Handling Events
document.images[0].addEventListener(
"click",
function() { alert( "I was clicked!" ); }
);
document.addEventListener(
"mousemove",
doMouseMove
);
Events are signals generated when specific actions
occur. JavaScript is aware of these signals and can
run scripts in reaction to them.
@krhoyt @mcorlan
Handling Events
@krhoyt @mcorlan
focus When a form element is selected
blur When a form element is deselected
change User updates a form element value
click Mouse is clicked on an element
mousedown The mouse is pressed
mousemove Mouse is moved while pressed
mouseup The mouse is released
touchstart A touch is started
touchmove A registred touch point has moved
touchend A touch has ended
And many more!
Selectors
Type: IMG, DIV, INPUT
Attribute: INPUT[type="text"]
Class: .green, INPUT.green
ID: #username, #password
Psuedo: DIV > p:first-child
@krhoyt @mcorlan
Selectors
var cat = null;
var cats = null;
cat = document.querySelector( '#cat' );
cats = document.querySelectorAll( '.cat' );
for( var c = 0; c < cats.length; c++ )
{
...
}
@krhoyt @mcorlan
Debugging
@krhoyt @mcorlan
+
Debugging
for( var m = 0; m < 10; m++ )
{
// Log value to developer tooling
console.log( 'Number is: ' + m );
}
// Stops execution
// Shows some value
alert( 'Done at: ' + m );
@krhoyt @mcorlan
What is JavaScript
1. Prototype-based
2. Scripting language
3. Dynamic
4. Weakly typed
5. First-class functions
6. Multi-paradigm
@krhoyt @mcorlan
Introduction to JavaScript
Hands-on
Getting Started with JavaScript
Kevin Hoyt and Mihai Corlan | Adobe

Contenu connexe

Tendances

Asp.docx(.net --3 year) programming
Asp.docx(.net --3 year) programmingAsp.docx(.net --3 year) programming
Asp.docx(.net --3 year) programmingAnkit Gupta
 
Cara membuka workbook yang terproteksi
Cara membuka workbook yang terproteksiCara membuka workbook yang terproteksi
Cara membuka workbook yang terproteksiIrmaoly
 
Java script how to
Java script how toJava script how to
Java script how tojulian vega
 
Mvvmintroduction 130725124207-phpapp01
Mvvmintroduction 130725124207-phpapp01Mvvmintroduction 130725124207-phpapp01
Mvvmintroduction 130725124207-phpapp01Nguyen Cuong
 
Dominando o Data Binding no Android
Dominando o Data Binding no AndroidDominando o Data Binding no Android
Dominando o Data Binding no AndroidNelson Glauber Leal
 
Dominando o Data Binding no Android
Dominando o Data Binding no AndroidDominando o Data Binding no Android
Dominando o Data Binding no AndroidNelson Glauber Leal
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)Shrijan Tiwari
 
Knockout vs. angular
Knockout vs. angularKnockout vs. angular
Knockout vs. angularMaslowB
 
Demystifying cache in doctrine ORM
Demystifying cache in doctrine ORMDemystifying cache in doctrine ORM
Demystifying cache in doctrine ORMLuís Cobucci
 
Web Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPageWeb Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPageSunny U Okoro
 

Tendances (20)

React.js 20150828
React.js 20150828React.js 20150828
React.js 20150828
 
Dwr explanation
Dwr explanationDwr explanation
Dwr explanation
 
Asp.docx(.net --3 year) programming
Asp.docx(.net --3 year) programmingAsp.docx(.net --3 year) programming
Asp.docx(.net --3 year) programming
 
Cara membuka workbook yang terproteksi
Cara membuka workbook yang terproteksiCara membuka workbook yang terproteksi
Cara membuka workbook yang terproteksi
 
Node js crash course session 6
Node js crash course   session 6Node js crash course   session 6
Node js crash course session 6
 
Java script how to
Java script how toJava script how to
Java script how to
 
Mvvmintroduction 130725124207-phpapp01
Mvvmintroduction 130725124207-phpapp01Mvvmintroduction 130725124207-phpapp01
Mvvmintroduction 130725124207-phpapp01
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
Dominando o Data Binding no Android
Dominando o Data Binding no AndroidDominando o Data Binding no Android
Dominando o Data Binding no Android
 
Dominando o Data Binding no Android
Dominando o Data Binding no AndroidDominando o Data Binding no Android
Dominando o Data Binding no Android
 
Web 5 | JavaScript Events
Web 5 | JavaScript EventsWeb 5 | JavaScript Events
Web 5 | JavaScript Events
 
2.java script dom
2.java script  dom2.java script  dom
2.java script dom
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
 
Java script objects
Java script objectsJava script objects
Java script objects
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)
 
Knockout vs. angular
Knockout vs. angularKnockout vs. angular
Knockout vs. angular
 
Demystifying cache in doctrine ORM
Demystifying cache in doctrine ORMDemystifying cache in doctrine ORM
Demystifying cache in doctrine ORM
 
Web Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPageWeb Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPage
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
 

En vedette

Flash and Hardware
Flash and HardwareFlash and Hardware
Flash and HardwareKevin Hoyt
 
Ignite A Cigar
Ignite A CigarIgnite A Cigar
Ignite A CigarKevin Hoyt
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Ignite a Cigar (Technical)
Ignite a Cigar (Technical)Ignite a Cigar (Technical)
Ignite a Cigar (Technical)Kevin Hoyt
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

En vedette (6)

Flash and Hardware
Flash and HardwareFlash and Hardware
Flash and Hardware
 
Ignite A Cigar
Ignite A CigarIgnite A Cigar
Ignite A Cigar
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Ignite a Cigar (Technical)
Ignite a Cigar (Technical)Ignite a Cigar (Technical)
Ignite a Cigar (Technical)
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similaire à Getting Started with JavaScript

Java script
 Java script Java script
Java scriptbosybosy
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJamshid Hashimi
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationSoumen Santra
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascriptsyeda zoya mehdi
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptDan Phiffer
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOMSukrit Gupta
 
Java script Learn Easy
Java script Learn Easy Java script Learn Easy
Java script Learn Easy prince Loffar
 
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridasFrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridasLoiane Groner
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptArti Parab Academics
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptxMuqaddarNiazi1
 

Similaire à Getting Started with JavaScript (20)

Java script
 Java script Java script
Java script
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Reacting to a Virtual World
Reacting to a Virtual WorldReacting to a Virtual World
Reacting to a Virtual World
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Java script
Java scriptJava script
Java script
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
 
Java script Learn Easy
Java script Learn Easy Java script Learn Easy
Java script Learn Easy
 
Javascript1
Javascript1Javascript1
Javascript1
 
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridasFrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 

Dernier

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 

Dernier (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 

Getting Started with JavaScript

  • 1. Introduction to JavaScript Hands-on Getting Started with JavaScript Kevin Hoyt and Mihai Corlan | Adobe
  • 2. About Us Kevin Hoyt @krhoyt Adobe Evangelist Mihai Corlan @mcorlan Adobe Evangelist
  • 3. What is JavaScript 1. Prototype-based 2. Scripting language 3. Dynamic 4. Weakly typed 5. First-class functions 6. Multi-paradigm @krhoyt @mcorlan
  • 4. Adding JavaScript to a Page - Inline <script type="text/javascript"> document.writeln( "It works!" ); </script> @krhoyt @mcorlan
  • 5. Adding JavaScript to a Page - External <script src="myscript.js" type="text/javascript"> </script> document.writeln( "It works!" ); In your HTML file: In the "myscript.js" file: @krhoyt @mcorlan
  • 6. Variables var _myName = "Mihai"; var hisName = "Kevin"; Variables are defined using the special keyword "var" followed by a valid name. Valid names can be any combination of letters, "$" and "_". @krhoyt @mcorlan
  • 7. Variable Types var myVar; // undefined var myVar = null; // null var myVar = 3.14; // Number var myVar = "MAX"; // String var myVar = true; // Boolean var myVar = { // Object first: "Mihai", last: "Corlan" }; @krhoyt @mcorlan
  • 8. Arrays var simpleArray = [1, 2, 3, 4]; var complexArray = new Array(); complexArray.push( 1 ); complexArray.push( "Kevin" ); An array is an ordered list of variables. Values inside the array can be of any type. You can even mix the types for each value. @krhoyt @mcorlan
  • 9. Custom Data Types An object is a collection of properties assigned to a single variable. var myVar = { index: 0, name: "Mihai Corlan", isAdobe: true }; @krhoyt @mcorlan
  • 10. Control Structures - if ... else var color = "red"; if( color === "red" ) // === vs. == { document.body.style.backgroundColor = "red"; } else if( color === "blue" ) { document.body.style.backgroundColor = "blue"; } else { document.body.style.backgroundColor = "#CCFFFF"; } @krhoyt @mcorlan
  • 11. Control Structures - switch ... case var color = "red"; switch( color ) { case "red": document.writeln( "It is red." ); break; case "blue": document.writeln( "It is blue." ); break; default: document.writeln( "Huh?" ); break; } @krhoyt @mcorlan
  • 12. Control Structures - for var div; var numbers = [1, 2, 3, 4, 5, 6]; for( var n = 0; n < numbers.length; n++ ) { div = document.createElement( "div" ); div.innerHTML = numbers[n]; div.style.fontSize = numbers[n] + "em"; document.body.appendChild( div ); } @krhoyt @mcorlan
  • 13. Control Structures - while var current = 0; var limit = 5; while( current < limit ) { document.writeln( current ); current = current + 1; } @krhoyt @mcorlan
  • 14. Control Structures - do ... while var current = 0; var limit = 5; do { document.writeln( current ); current = current + 1; } while( current < limit ); @krhoyt @mcorlan
  • 15. Functions function sayHello() { document.writeln( "Hello World!" ); } sayHello(); A function is a block of code that will be executed when it is called. Functions allow you to reuse code that needs to be executed more than once, or in more than one place. @krhoyt @mcorlan
  • 16. Functions - Arguments and Return Values function addNumbers( value1, value2 ) { return value1 + value2; } var sum = addNumbers( 2, 2 ); document.writeln( sum ); @krhoyt @mcorlan
  • 17. Variable Scope var value = 0; function tellMe() { var value = 1; document.writeln( value ); } tellMe(); // Will be 1 document.writeln( value ); // Will be 0 JavaScript has one "global" scope. Each function also has its own scope. If you omit "var" then values default to the global scope. @krhoyt @mcorlan
  • 18. Handling Events document.images[0].addEventListener( "click", function() { alert( "I was clicked!" ); } ); document.addEventListener( "mousemove", doMouseMove ); Events are signals generated when specific actions occur. JavaScript is aware of these signals and can run scripts in reaction to them. @krhoyt @mcorlan
  • 19. Handling Events @krhoyt @mcorlan focus When a form element is selected blur When a form element is deselected change User updates a form element value click Mouse is clicked on an element mousedown The mouse is pressed mousemove Mouse is moved while pressed mouseup The mouse is released touchstart A touch is started touchmove A registred touch point has moved touchend A touch has ended And many more!
  • 20. Selectors Type: IMG, DIV, INPUT Attribute: INPUT[type="text"] Class: .green, INPUT.green ID: #username, #password Psuedo: DIV > p:first-child @krhoyt @mcorlan
  • 21. Selectors var cat = null; var cats = null; cat = document.querySelector( '#cat' ); cats = document.querySelectorAll( '.cat' ); for( var c = 0; c < cats.length; c++ ) { ... } @krhoyt @mcorlan
  • 23. Debugging for( var m = 0; m < 10; m++ ) { // Log value to developer tooling console.log( 'Number is: ' + m ); } // Stops execution // Shows some value alert( 'Done at: ' + m ); @krhoyt @mcorlan
  • 24. What is JavaScript 1. Prototype-based 2. Scripting language 3. Dynamic 4. Weakly typed 5. First-class functions 6. Multi-paradigm @krhoyt @mcorlan
  • 25. Introduction to JavaScript Hands-on Getting Started with JavaScript Kevin Hoyt and Mihai Corlan | Adobe