SlideShare a Scribd company logo
1 of 30
DESIGNVELOPER
JavaScript Introduction
• JavaScript is the most popular programming
language in the world.
• JavaScript is the language for the web
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Variables
• Declaring:
– var x=10
– var y
• Global variable:
Declaring : x=0;
• Local variable
Declaring : var x=0
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Objects
• Almost "everything" in JavaScript can be
objects. Strings, Dates, Arrays, Functions....
• There are many different ways to create new
JavaScript objects, and you can also add new
properties and methods to already existing
objects.
• Example:
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Creating JavaScript Objects
• Methods defined internally
function Apple (type) {
this.type = type;
this.color = "red";
this.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
}
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Creating JavaScript Objects
• Methods added to the prototype
function Apple (type)
{
this.type = type;
this.color = "red";
}
Apple.prototype.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Creating JavaScript Objects
• To instantiate an object using the
Apple constructor function, set some
properties and call methods you can do the
following:
• var apple = new Apple('macintosh');
apple.color = "reddish";
alert(apple.getInfo());
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Using object literals
• Literals are shorter way to define objects and
arrays in JavaScript. To create an empty object
using you can do:
var o = {};
instead of the "normal" way:
var o = new Object();
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Using object literals
• var apple = {
type: "macintosh",
color: "red",
getInfo: function () {
return this.color + ' ' + this.type + ' apple';
}
}
In this case you don't need to (and cannot) create an instance of
the class, it already exists. So you simply start using this instance.
apple.color = "reddish";
alert(apple.getInfo());
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Singleton using a function
• You can use a function to define a singleton
object. Here's the syntax:
var apple = new function() {
this.type = "macintosh";
this.color = "red";
this.getInfo = function () {
return this.color + ' ' + this.type + ' apple';
};
}
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Singleton using a function
• So you see that this is very similar to 1.
discussed above, but the way to use the
object is exactly like in 2.
apple.color = "reddish";
alert(apple.getInfo());
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Functions
• JavaScript Numbers
• JavaScript Strings
• JavaScript Dates
• JavaScript Arrays
• JavaScript Booleans
• JavaScript Maths
• JavaScript Operators
• JavaScript If...Else Statements
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Switch Statement
• JavaScript For Loop
• JavaScript While Loop
• JavaScript Break and Continue
• JavaScript Errors - Throw and Try to Catch
• JavaScript Form Validation
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript HTML DOM
• With the object model, JavaScript gets all the power it
needs to create dynamic HTML:
• JavaScript can change all the HTML elements in the page
• JavaScript can change all the HTML attributes in the page
• JavaScript can change all the CSS styles in the page
• JavaScript can remove existing HTML elements and
attributes
• JavaScript can add new HTML elements and attributes
• JavaScript can react to all existing HTML events in the page
• JavaScript can create new HTML events in the page
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript - HTML DOM Methods
• HTML DOM methods are actions you can
perform (on HTML Elements)
• HTML DOM properties are values (of HTML
Elements) that you can set or change
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript HTML DOM Document
• In the HTML DOM object model, the
document object represents your web page.
• The document object is the owner of all other
objects in your web page.
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript HTML DOM - Changing HTML
• JavaScript HTML DOM - Changing CSS
– <p id="p2">Hello World!</p>
<script>
document.getElementById("p2").style.color="blue";
</script>
<p>The paragraph above was changed by a script.</p>
JavaScript HTML DOM Event
• JavaScript HTML DOM Events
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript HTML DOM Elements
(Nodes)
• To add a new element to the HTML DOM, you must create
the element (element node) first, and then append it to an
existing element.
• <div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
var para=document.createElement("p");
var node=document.createTextNode("This is new.");
para.appendChild(node);
var element=document.getElementById("div1");
element.appendChild(para);
</script>
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
HTML DOM Node List Length
• The length property defines the number of nodes
in a node-list.
• You can loop through a node-list by using the
length property:
• x=document.getElementsByTagName("p");
for (i=0;i<x.length;i++)
{
document.write(x[i].innerHTML);
document.write("<br />");
}
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
The Browser Object Model
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
The Browser Object Model
• The window object is supported by all browsers. It
represent the browser's window.
• For Internet Explorer, Chrome, Firefox, Opera, and Safari:
– window.innerHeight - the inner height of the browser window
– window.innerWidth - the inner width of the browser window
• For Internet Explorer 8, 7, 6, 5:
– document.documentElement.clientHeight
– document.documentElement.clientWidth
– or
– document.body.clientHeight
– document.body.clientWidth
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
The Browser Object Model
• Some other methods:
– window.open() - open a new window
– window.close() - close the current window
– window.moveTo() -move the current window
– window.resizeTo() -resize the current window
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Window Screen
– screen.availWidth - available screen width
– screen.availHeight - available screen height
• JavaScript Window Location
– location.hostname returns the domain name of the
web host
– location.pathname returns the path and filename of
the current page
– location.port returns the port of the web host (80 or
443)
– location.protocol returns the web protocol used
(http:// or https://)
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Window History
– history.back() - same as clicking back in the
browser
– history.forward() - same as clicking forward in the
browser
• JavaScript Window Navigator
– The window.navigator object contains information
about the visitor's browser.
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Popup Boxes
– Alert Box
– Confirm Box
– Prompt Box
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Timing Events
• setInterval() - executes a function, over and
over again, at specified time intervals
• setTimeout() - executes a function, once, after
waiting a specified number of milliseconds
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Cookies
• Create a Cookie with JavaScript
– document.cookie="username=John Doe";
• You can also add an expiry date (in UTC or
GMT time). By default, the cookie is deleted
when the browser is closed:
– document.cookie="username=John Doe;
expires=Thu, 18 Dec 2013 12:00:00 GMT; path=/";
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Cookies
• Delete a Cookie with JavaScript
– document.cookie = "username=; expires=Thu, 01
Jan 1970 00:00:00 GMT";
• Read a Cookie with JavaScript
– var x = document.cookie;
document.cookie will return all cookies in one string
much like: cookie1=value; cookie2=value;
cookie3=value;
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript RegExp Object
• JavaScript RegExp Object
• A regular expression is an object that
describes a pattern of characters.
• When you search in a text, you can use a
pattern to describe what you are searching for.
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Java Script Ajax
• AJAX is the art of exchanging data with a
server, and updating parts of a web page -
without reloading the whole page.
• How AJAX Works
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City

More Related Content

What's hot

Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017Henry Van Styn
 
JS digest. April 2018
JS digest. April 2018JS digest. April 2018
JS digest. April 2018ElifTech
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5Derek Jacoby
 
Untangling spring week4
Untangling spring week4Untangling spring week4
Untangling spring week4Derek Jacoby
 
RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014Henry Van Styn
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Mike Schinkel
 

What's hot (6)

Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017
 
JS digest. April 2018
JS digest. April 2018JS digest. April 2018
JS digest. April 2018
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5
 
Untangling spring week4
Untangling spring week4Untangling spring week4
Untangling spring week4
 
RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 

Viewers also liked

Présentation JavaScript
Présentation JavaScriptPrésentation JavaScript
Présentation JavaScripttarkan_
 
JavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesJavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesOleksii Prohonnyi
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptBryan Basham
 
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)Mudularity and Unit Testing in TypeScript (for ng-bkk #3)
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)Suthep Sangvirotjanaphat
 

Viewers also liked (6)

The Role Of Java Script
The Role Of Java ScriptThe Role Of Java Script
The Role Of Java Script
 
Présentation JavaScript
Présentation JavaScriptPrésentation JavaScript
Présentation JavaScript
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
JavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesJavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and Libraries
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)Mudularity and Unit Testing in TypeScript (for ng-bkk #3)
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)
 

Similar to JavaScript Introduction

Creating a CSS layout from scratch
Creating a CSS layout from scratchCreating a CSS layout from scratch
Creating a CSS layout from scratchDesignveloper
 
Javascript template engine
Javascript template engineJavascript template engine
Javascript template engineDesignveloper
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQueryMark Rackley
 
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointMark Rackley
 
Introduction to Foundation
Introduction to FoundationIntroduction to Foundation
Introduction to FoundationDesignveloper
 
HTML5 features & JavaScript APIs
HTML5 features & JavaScript APIsHTML5 features & JavaScript APIs
HTML5 features & JavaScript APIsFisnik Doko
 
BACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JSBACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JSDesignveloper
 
PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentCindy Royal
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizationsChris Love
 
Back to the 90s' - Revenge of the static website
Back to the 90s' - Revenge of the static websiteBack to the 90s' - Revenge of the static website
Back to the 90s' - Revenge of the static websiteYves Goeleven
 
How to Build a Bespoke Page Builder in WordPress
How to Build a Bespoke Page Builder in WordPressHow to Build a Bespoke Page Builder in WordPress
How to Build a Bespoke Page Builder in WordPressGerald Glynn
 
SPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuideSPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuideMark Rackley
 
Building high performance
Building high performanceBuilding high performance
Building high performanceRoy Sheinfeld
 
Building Faster Websites
Building Faster WebsitesBuilding Faster Websites
Building Faster WebsitesCraig Walker
 
Lect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptxLect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptxzainm7032
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkBob German
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on RailsAvi Kedar
 
German introduction to sp framework
German   introduction to sp frameworkGerman   introduction to sp framework
German introduction to sp frameworkBob German
 

Similar to JavaScript Introduction (20)

Jquery
JqueryJquery
Jquery
 
Creating a CSS layout from scratch
Creating a CSS layout from scratchCreating a CSS layout from scratch
Creating a CSS layout from scratch
 
Javascript template engine
Javascript template engineJavascript template engine
Javascript template engine
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
 
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
 
Introduction to Foundation
Introduction to FoundationIntroduction to Foundation
Introduction to Foundation
 
performance.ppt
performance.pptperformance.ppt
performance.ppt
 
HTML5 features & JavaScript APIs
HTML5 features & JavaScript APIsHTML5 features & JavaScript APIs
HTML5 features & JavaScript APIs
 
BACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JSBACKBONE.JS & UNDERSCORE.JS
BACKBONE.JS & UNDERSCORE.JS
 
PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web Development
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
 
Back to the 90s' - Revenge of the static website
Back to the 90s' - Revenge of the static websiteBack to the 90s' - Revenge of the static website
Back to the 90s' - Revenge of the static website
 
How to Build a Bespoke Page Builder in WordPress
How to Build a Bespoke Page Builder in WordPressHow to Build a Bespoke Page Builder in WordPress
How to Build a Bespoke Page Builder in WordPress
 
SPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuideSPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuide
 
Building high performance
Building high performanceBuilding high performance
Building high performance
 
Building Faster Websites
Building Faster WebsitesBuilding Faster Websites
Building Faster Websites
 
Lect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptxLect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptx
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint Framework
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
German introduction to sp framework
German   introduction to sp frameworkGerman   introduction to sp framework
German introduction to sp framework
 

More from Designveloper

Let us take care of your brand image
Let us take care of your brand imageLet us take care of your brand image
Let us take care of your brand imageDesignveloper
 
5 java script frameworks to watch in 2017
5 java script frameworks to watch in 20175 java script frameworks to watch in 2017
5 java script frameworks to watch in 2017Designveloper
 
Happy international women's day!
Happy international women's day!Happy international women's day!
Happy international women's day!Designveloper
 
Typing racer game - a nice break from work
Typing racer game  - a nice break from workTyping racer game  - a nice break from work
Typing racer game - a nice break from workDesignveloper
 
Should we work remotely?
Should we work remotely?Should we work remotely?
Should we work remotely?Designveloper
 
Meet song nhi your virtual financial assistance
Meet song nhi   your virtual financial assistanceMeet song nhi   your virtual financial assistance
Meet song nhi your virtual financial assistanceDesignveloper
 
Why pair programming is a good idea
Why pair programming is a good idea Why pair programming is a good idea
Why pair programming is a good idea Designveloper
 
5 worst mistakes of diy websites
5 worst mistakes of diy websites5 worst mistakes of diy websites
5 worst mistakes of diy websitesDesignveloper
 
Basic glossary of web design terms for non designers (part 2)
Basic glossary of web design terms for non designers (part 2)Basic glossary of web design terms for non designers (part 2)
Basic glossary of web design terms for non designers (part 2)Designveloper
 
Single page web application development using meteor js
Single page web application development using meteor jsSingle page web application development using meteor js
Single page web application development using meteor jsDesignveloper
 
Multiplayer game with unity3 d and meteor
Multiplayer game with unity3 d and meteorMultiplayer game with unity3 d and meteor
Multiplayer game with unity3 d and meteorDesignveloper
 
Awesome free resources for learning javascript
Awesome free resources for learning javascriptAwesome free resources for learning javascript
Awesome free resources for learning javascriptDesignveloper
 
What is the best java script frameworks to learn?
What is the best java script frameworks to learn?What is the best java script frameworks to learn?
What is the best java script frameworks to learn?Designveloper
 
Travelling forms a young man
Travelling forms a young manTravelling forms a young man
Travelling forms a young manDesignveloper
 
5 compelling reasons your website should be responsive
5 compelling reasons your website should be responsive5 compelling reasons your website should be responsive
5 compelling reasons your website should be responsiveDesignveloper
 
Reactive programming with tracker
Reactive programming with trackerReactive programming with tracker
Reactive programming with trackerDesignveloper
 
Benefits of using single page websites
Benefits of using single page websitesBenefits of using single page websites
Benefits of using single page websitesDesignveloper
 
What is the best programming language for beginner?
What is the best programming language for beginner?What is the best programming language for beginner?
What is the best programming language for beginner?Designveloper
 
No sql injection in meteor.js application
No sql injection in meteor.js applicationNo sql injection in meteor.js application
No sql injection in meteor.js applicationDesignveloper
 
How to deploy and scale your meteor apps
How to deploy and scale your meteor appsHow to deploy and scale your meteor apps
How to deploy and scale your meteor appsDesignveloper
 

More from Designveloper (20)

Let us take care of your brand image
Let us take care of your brand imageLet us take care of your brand image
Let us take care of your brand image
 
5 java script frameworks to watch in 2017
5 java script frameworks to watch in 20175 java script frameworks to watch in 2017
5 java script frameworks to watch in 2017
 
Happy international women's day!
Happy international women's day!Happy international women's day!
Happy international women's day!
 
Typing racer game - a nice break from work
Typing racer game  - a nice break from workTyping racer game  - a nice break from work
Typing racer game - a nice break from work
 
Should we work remotely?
Should we work remotely?Should we work remotely?
Should we work remotely?
 
Meet song nhi your virtual financial assistance
Meet song nhi   your virtual financial assistanceMeet song nhi   your virtual financial assistance
Meet song nhi your virtual financial assistance
 
Why pair programming is a good idea
Why pair programming is a good idea Why pair programming is a good idea
Why pair programming is a good idea
 
5 worst mistakes of diy websites
5 worst mistakes of diy websites5 worst mistakes of diy websites
5 worst mistakes of diy websites
 
Basic glossary of web design terms for non designers (part 2)
Basic glossary of web design terms for non designers (part 2)Basic glossary of web design terms for non designers (part 2)
Basic glossary of web design terms for non designers (part 2)
 
Single page web application development using meteor js
Single page web application development using meteor jsSingle page web application development using meteor js
Single page web application development using meteor js
 
Multiplayer game with unity3 d and meteor
Multiplayer game with unity3 d and meteorMultiplayer game with unity3 d and meteor
Multiplayer game with unity3 d and meteor
 
Awesome free resources for learning javascript
Awesome free resources for learning javascriptAwesome free resources for learning javascript
Awesome free resources for learning javascript
 
What is the best java script frameworks to learn?
What is the best java script frameworks to learn?What is the best java script frameworks to learn?
What is the best java script frameworks to learn?
 
Travelling forms a young man
Travelling forms a young manTravelling forms a young man
Travelling forms a young man
 
5 compelling reasons your website should be responsive
5 compelling reasons your website should be responsive5 compelling reasons your website should be responsive
5 compelling reasons your website should be responsive
 
Reactive programming with tracker
Reactive programming with trackerReactive programming with tracker
Reactive programming with tracker
 
Benefits of using single page websites
Benefits of using single page websitesBenefits of using single page websites
Benefits of using single page websites
 
What is the best programming language for beginner?
What is the best programming language for beginner?What is the best programming language for beginner?
What is the best programming language for beginner?
 
No sql injection in meteor.js application
No sql injection in meteor.js applicationNo sql injection in meteor.js application
No sql injection in meteor.js application
 
How to deploy and scale your meteor apps
How to deploy and scale your meteor appsHow to deploy and scale your meteor apps
How to deploy and scale your meteor apps
 

Recently uploaded

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Recently uploaded (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

JavaScript Introduction

  • 1. DESIGNVELOPER JavaScript Introduction • JavaScript is the most popular programming language in the world. • JavaScript is the language for the web Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 2. JavaScript Variables • Declaring: – var x=10 – var y • Global variable: Declaring : x=0; • Local variable Declaring : var x=0 Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 3. JavaScript Objects • Almost "everything" in JavaScript can be objects. Strings, Dates, Arrays, Functions.... • There are many different ways to create new JavaScript objects, and you can also add new properties and methods to already existing objects. • Example: Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 4. Creating JavaScript Objects • Methods defined internally function Apple (type) { this.type = type; this.color = "red"; this.getInfo = function() { return this.color + ' ' + this.type + ' apple'; }; } Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 5. Creating JavaScript Objects • Methods added to the prototype function Apple (type) { this.type = type; this.color = "red"; } Apple.prototype.getInfo = function() { return this.color + ' ' + this.type + ' apple'; }; Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 6. Creating JavaScript Objects • To instantiate an object using the Apple constructor function, set some properties and call methods you can do the following: • var apple = new Apple('macintosh'); apple.color = "reddish"; alert(apple.getInfo()); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 7. Using object literals • Literals are shorter way to define objects and arrays in JavaScript. To create an empty object using you can do: var o = {}; instead of the "normal" way: var o = new Object(); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 8. Using object literals • var apple = { type: "macintosh", color: "red", getInfo: function () { return this.color + ' ' + this.type + ' apple'; } } In this case you don't need to (and cannot) create an instance of the class, it already exists. So you simply start using this instance. apple.color = "reddish"; alert(apple.getInfo()); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 9. Singleton using a function • You can use a function to define a singleton object. Here's the syntax: var apple = new function() { this.type = "macintosh"; this.color = "red"; this.getInfo = function () { return this.color + ' ' + this.type + ' apple'; }; } Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 10. Singleton using a function • So you see that this is very similar to 1. discussed above, but the way to use the object is exactly like in 2. apple.color = "reddish"; alert(apple.getInfo()); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 11. • JavaScript Functions • JavaScript Numbers • JavaScript Strings • JavaScript Dates • JavaScript Arrays • JavaScript Booleans • JavaScript Maths • JavaScript Operators • JavaScript If...Else Statements Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 12. • JavaScript Switch Statement • JavaScript For Loop • JavaScript While Loop • JavaScript Break and Continue • JavaScript Errors - Throw and Try to Catch • JavaScript Form Validation Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 13. JavaScript HTML DOM • With the object model, JavaScript gets all the power it needs to create dynamic HTML: • JavaScript can change all the HTML elements in the page • JavaScript can change all the HTML attributes in the page • JavaScript can change all the CSS styles in the page • JavaScript can remove existing HTML elements and attributes • JavaScript can add new HTML elements and attributes • JavaScript can react to all existing HTML events in the page • JavaScript can create new HTML events in the page Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 14. JavaScript - HTML DOM Methods • HTML DOM methods are actions you can perform (on HTML Elements) • HTML DOM properties are values (of HTML Elements) that you can set or change Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 15. JavaScript HTML DOM Document • In the HTML DOM object model, the document object represents your web page. • The document object is the owner of all other objects in your web page. Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 16. • JavaScript HTML DOM - Changing HTML • JavaScript HTML DOM - Changing CSS – <p id="p2">Hello World!</p> <script> document.getElementById("p2").style.color="blue"; </script> <p>The paragraph above was changed by a script.</p> JavaScript HTML DOM Event • JavaScript HTML DOM Events Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 17. JavaScript HTML DOM Elements (Nodes) • To add a new element to the HTML DOM, you must create the element (element node) first, and then append it to an existing element. • <div id="div1"> <p id="p1">This is a paragraph.</p> <p id="p2">This is another paragraph.</p> </div> <script> var para=document.createElement("p"); var node=document.createTextNode("This is new."); para.appendChild(node); var element=document.getElementById("div1"); element.appendChild(para); </script> Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 18. HTML DOM Node List Length • The length property defines the number of nodes in a node-list. • You can loop through a node-list by using the length property: • x=document.getElementsByTagName("p"); for (i=0;i<x.length;i++) { document.write(x[i].innerHTML); document.write("<br />"); } Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 19. The Browser Object Model Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 20. The Browser Object Model • The window object is supported by all browsers. It represent the browser's window. • For Internet Explorer, Chrome, Firefox, Opera, and Safari: – window.innerHeight - the inner height of the browser window – window.innerWidth - the inner width of the browser window • For Internet Explorer 8, 7, 6, 5: – document.documentElement.clientHeight – document.documentElement.clientWidth – or – document.body.clientHeight – document.body.clientWidth Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 21. The Browser Object Model • Some other methods: – window.open() - open a new window – window.close() - close the current window – window.moveTo() -move the current window – window.resizeTo() -resize the current window Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 22. • JavaScript Window Screen – screen.availWidth - available screen width – screen.availHeight - available screen height • JavaScript Window Location – location.hostname returns the domain name of the web host – location.pathname returns the path and filename of the current page – location.port returns the port of the web host (80 or 443) – location.protocol returns the web protocol used (http:// or https://) Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 23. • JavaScript Window History – history.back() - same as clicking back in the browser – history.forward() - same as clicking forward in the browser • JavaScript Window Navigator – The window.navigator object contains information about the visitor's browser. Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 24. • JavaScript Popup Boxes – Alert Box – Confirm Box – Prompt Box Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 25. JavaScript Timing Events • setInterval() - executes a function, over and over again, at specified time intervals • setTimeout() - executes a function, once, after waiting a specified number of milliseconds Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 26. JavaScript Cookies • Create a Cookie with JavaScript – document.cookie="username=John Doe"; • You can also add an expiry date (in UTC or GMT time). By default, the cookie is deleted when the browser is closed: – document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 GMT; path=/"; Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 27. JavaScript Cookies • Delete a Cookie with JavaScript – document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 GMT"; • Read a Cookie with JavaScript – var x = document.cookie; document.cookie will return all cookies in one string much like: cookie1=value; cookie2=value; cookie3=value; Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 28. JavaScript RegExp Object • JavaScript RegExp Object • A regular expression is an object that describes a pattern of characters. • When you search in a text, you can use a pattern to describe what you are searching for. Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 29. Java Script Ajax • AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page. • How AJAX Works Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 30. Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City