SlideShare a Scribd company logo
1 of 13
JavaScript Basics 
PRESENTED BY: HASSAN AHMED BAIG
Introduction 
JavaScript is the programming language of the Web that runs on client end. 
All modern HTML pages are using JavaScript. 
JavaScript enhances Web pages with dynamic and interactive features like: 
 Shopping carts 
 Form Validation 
 Calculations 
 Special graphic and text effects 
 Image swapping 
 and many more.
Advantages and Disadvantages 
ADVANTAGES 
Runs Fast: Most of the JavaScript task runs 
without contacting to the server. 
Platform Independent. 
Easy to Learn. 
Increased interactivity: You can create 
interfaces that react on the user interactions. 
Richer interfaces: You can use JavaScript to 
include such items as drag-and-drop 
components and sliders to give a Rich 
Interface to your site visitors. 
DISADVANTAGES 
Runs on single thread: There is no 
multithreading or multiprocessing capabilities. 
Read/Write Files: JavaScript does not allow 
the reading or writing of files. This has been 
kept for security reason. 
Networking applications: JavaScript can not 
be used for Networking applications because 
there is no such support available. 
Code is not hidden: Code is always visible to 
client end, even though it is minified.
Where JavaScript Is Placed 
In HTML, JavaScripts must be inserted between <script> and </script> tags either in <head> or 
<body> tag. 
<html> 
<head> 
<script> 
</script> 
</head> 
<body> 
<script> 
</script> 
</body> 
</html> 
JavaScript code comes here. 
External JavaScript can also be inserted using “<script src="myScript.js"></script>”.
JavaScript Syntax (Variables) 
For single line comments “//” is used and for multiline comments “/* */” is used. 
Variables are declared using “var” keyword. 
var pi = 3.14; 
var person = “Hassan Ahmed Baig“, var company= ’eDev’; 
var x = 5; 
var tested = true; 
var lastName = “Baig", x = 30, job = “Developer"; 
var carName; 
var cars = ["Saab", "Volvo", "BMW"]; 
var person = {firstName:“Hassan", lastName:“Baig", age:50, job:“Developer"}; 
Floating, String, 
Numeric and 
boolean Variables 
One Statement, Many Variables 
If value is not defined 
Arrays are defined then Value = Undefined 
using square brackets 
In JavaScript Objects properties 
are written in key value pair. 
Properties can be accessed as 
“person.firstName”.
JavaScript Syntax (Functions and Events) 
For adding functions in JavaScript “function” keyword is used. 
function functionName(param1, param2,…,paramN){ 
//Code to be executed. 
return anyValue; //return is used if function return any value otherwise not. 
} 
Functions can be accessed by their names like “functionName(1,2);” 
Functions can be called any event occur like onclick event of button. 
<button onclick=“functionName()”>Press It</button> 
In Events single statement can also be executed with out calling the function. 
<button onclick=“this.innerHTML=Date()”>Press It</button>
JavaScript Syntax (Conditions) 
Conditions in JavaScript are “if”, “if else”, “if else if” and “switch”. 
if (condition) { 
code to be executed if the condition is true 
} 
if (condition) { 
code to be executed if the condition is true 
}else{ 
code to be executed if the condition is false 
} 
if (condition1) { 
code to be executed if condition1 is true 
} else if (condition2) { 
code to be executed if the condition1 is false and condition2 is true 
} else { 
code to be executed if the condition1 is false and condition2 is false 
} 
switch(expression) { 
case n: 
code block 
break; 
case n: 
code block 
break; 
default: 
default code block 
}
JavaScript Syntax (Loops) 
Loops in JavaScript are “for”, “for/in”, “while” and “do/while”. 
for (initialization; condition; increment) { 
code block to be executed 
} 
For example: 
for (i = 0; i < 5; i++) { 
text += "The number is " + i + "<br>"; 
} 
For/in is used to iterate the properties of an object. 
var person = {fname:“Hassan”, lname:“Baig”, age:50}; 
var text = ""; 
var propertyName; 
for (propertyName in person) { 
text += “PropertyName: ” + propertyName; 
text += “PropertyValue: ” + person[propertyName ]; 
} 
while (condition) { 
code block to be executed 
} 
do { 
code block to be executed 
} 
while (condition);
JavaScript HTML DOM 
With the HTML DOM, JavaScript can access and change all the elements of an HTML document. 
In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML 
elements. 
When web page is loaded, browser creates a Document Object Model of the page as for 
example: 
<html> 
<head> 
<title> 
My title 
</title> 
</head> 
<body> 
<a href=“#”>My link</a> 
<h1>My header</h1> 
</body> 
</html>
Finding Element In HTML DOM 
Elements can be found by their “ID”, “Tag Name”, “Class Name”. 
“document.getElementById()” is used to find the element by their ids. 
“document.getElementsByTagName()” is used to find the element by the tag name. 
 Eg: document. getElementsByTagName(“header”); 
“document.getElementsByClassName()” is used to find the element by the class name. 
 Eg: document. getElementsByClassName(“logo”);
Changing HTML 
HTML of any element can be modified by “innerHTML” property as follows: 
Value of any attribute of an element can also be changed as follows: 
<p id=“name"><strong>Hassan 
</strong></p> 
Hassan 
document.getElementById(“name”).innerHTML = ”<strong>Hassan</strong>” 
<p id=“name">Hassan</p> 
Hassan 
document.getElementById(“<img src=“abc.jpg” > name”).src= ”xyz.jpg” <img src=“xyz.jpg” >
Changing CSS 
Style of any element can be modified by “style” property as follows: 
<p id=“name“ style=“color:blue”>Hassan</p> 
Hassan 
document.getElementById(“name”).style.color = ”blue” 
<p id=“name">Hassan</p> 
Hassan 
document.getElementById(id).style.property=new style
Register Event Using HTML DOM 
Events can also be registered to any element using JavaScript HTML DOM as follows: 
document.getElementById("myBtn").onclick = function(){ 
//code to be executed. 
};

More Related Content

What's hot

Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSSAmit Tyagi
 
javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - IntroductionWebStackAcademy
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - OperatorsWebStackAcademy
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginnersSingsys Pte Ltd
 

What's hot (20)

Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Web Development using HTML & CSS
Web Development using HTML & CSSWeb Development using HTML & CSS
Web Development using HTML & CSS
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
css.ppt
css.pptcss.ppt
css.ppt
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginners
 

Viewers also liked

Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript TutorialDHTMLExtreme
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Languageguestceb98b
 
JavaScript 101 for Microsoft CRM 2011
JavaScript 101 for Microsoft CRM 2011JavaScript 101 for Microsoft CRM 2011
JavaScript 101 for Microsoft CRM 2011Will Slade
 
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLEDEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLEVaibhav Sinha
 
HTML Frameset & Inline Frame
HTML Frameset & Inline FrameHTML Frameset & Inline Frame
HTML Frameset & Inline FrameNisa Soomro
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML formsNadine Cruz
 
Javascript & OData Microsoft Dynamics CRM
Javascript & OData Microsoft Dynamics CRMJavascript & OData Microsoft Dynamics CRM
Javascript & OData Microsoft Dynamics CRMAshish Vishwakarma
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Chris Poteet
 

Viewers also liked (14)

Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Javascript
JavascriptJavascript
Javascript
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
JavaScript 101 for Microsoft CRM 2011
JavaScript 101 for Microsoft CRM 2011JavaScript 101 for Microsoft CRM 2011
JavaScript 101 for Microsoft CRM 2011
 
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLEDEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
 
Html frames
Html framesHtml frames
Html frames
 
HTML Frameset & Inline Frame
HTML Frameset & Inline FrameHTML Frameset & Inline Frame
HTML Frameset & Inline Frame
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML forms
 
Html Frames
Html FramesHtml Frames
Html Frames
 
Javascript
JavascriptJavascript
Javascript
 
Javascript & OData Microsoft Dynamics CRM
Javascript & OData Microsoft Dynamics CRMJavascript & OData Microsoft Dynamics CRM
Javascript & OData Microsoft Dynamics CRM
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Js ppt
Js pptJs ppt
Js ppt
 

Similar to Introduction to JavaScript Basics.

eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1Paras Mendiratta
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students shafiq sangi
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scriptingpkaviya
 
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
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Lookrumsan
 
Java script
 Java script Java script
Java scriptbosybosy
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulationborkweb
 
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
 

Similar to Introduction to JavaScript Basics. (20)

Java script
Java scriptJava script
Java script
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
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
 
Java script
Java scriptJava script
Java script
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
 
Java script
 Java script Java script
Java script
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
Java script
Java scriptJava script
Java script
 
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
 
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
 
Web programming
Web programmingWeb programming
Web programming
 

Recently uploaded

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Introduction to JavaScript Basics.

  • 1. JavaScript Basics PRESENTED BY: HASSAN AHMED BAIG
  • 2. Introduction JavaScript is the programming language of the Web that runs on client end. All modern HTML pages are using JavaScript. JavaScript enhances Web pages with dynamic and interactive features like:  Shopping carts  Form Validation  Calculations  Special graphic and text effects  Image swapping  and many more.
  • 3. Advantages and Disadvantages ADVANTAGES Runs Fast: Most of the JavaScript task runs without contacting to the server. Platform Independent. Easy to Learn. Increased interactivity: You can create interfaces that react on the user interactions. Richer interfaces: You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors. DISADVANTAGES Runs on single thread: There is no multithreading or multiprocessing capabilities. Read/Write Files: JavaScript does not allow the reading or writing of files. This has been kept for security reason. Networking applications: JavaScript can not be used for Networking applications because there is no such support available. Code is not hidden: Code is always visible to client end, even though it is minified.
  • 4. Where JavaScript Is Placed In HTML, JavaScripts must be inserted between <script> and </script> tags either in <head> or <body> tag. <html> <head> <script> </script> </head> <body> <script> </script> </body> </html> JavaScript code comes here. External JavaScript can also be inserted using “<script src="myScript.js"></script>”.
  • 5. JavaScript Syntax (Variables) For single line comments “//” is used and for multiline comments “/* */” is used. Variables are declared using “var” keyword. var pi = 3.14; var person = “Hassan Ahmed Baig“, var company= ’eDev’; var x = 5; var tested = true; var lastName = “Baig", x = 30, job = “Developer"; var carName; var cars = ["Saab", "Volvo", "BMW"]; var person = {firstName:“Hassan", lastName:“Baig", age:50, job:“Developer"}; Floating, String, Numeric and boolean Variables One Statement, Many Variables If value is not defined Arrays are defined then Value = Undefined using square brackets In JavaScript Objects properties are written in key value pair. Properties can be accessed as “person.firstName”.
  • 6. JavaScript Syntax (Functions and Events) For adding functions in JavaScript “function” keyword is used. function functionName(param1, param2,…,paramN){ //Code to be executed. return anyValue; //return is used if function return any value otherwise not. } Functions can be accessed by their names like “functionName(1,2);” Functions can be called any event occur like onclick event of button. <button onclick=“functionName()”>Press It</button> In Events single statement can also be executed with out calling the function. <button onclick=“this.innerHTML=Date()”>Press It</button>
  • 7. JavaScript Syntax (Conditions) Conditions in JavaScript are “if”, “if else”, “if else if” and “switch”. if (condition) { code to be executed if the condition is true } if (condition) { code to be executed if the condition is true }else{ code to be executed if the condition is false } if (condition1) { code to be executed if condition1 is true } else if (condition2) { code to be executed if the condition1 is false and condition2 is true } else { code to be executed if the condition1 is false and condition2 is false } switch(expression) { case n: code block break; case n: code block break; default: default code block }
  • 8. JavaScript Syntax (Loops) Loops in JavaScript are “for”, “for/in”, “while” and “do/while”. for (initialization; condition; increment) { code block to be executed } For example: for (i = 0; i < 5; i++) { text += "The number is " + i + "<br>"; } For/in is used to iterate the properties of an object. var person = {fname:“Hassan”, lname:“Baig”, age:50}; var text = ""; var propertyName; for (propertyName in person) { text += “PropertyName: ” + propertyName; text += “PropertyValue: ” + person[propertyName ]; } while (condition) { code block to be executed } do { code block to be executed } while (condition);
  • 9. JavaScript HTML DOM With the HTML DOM, JavaScript can access and change all the elements of an HTML document. In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML elements. When web page is loaded, browser creates a Document Object Model of the page as for example: <html> <head> <title> My title </title> </head> <body> <a href=“#”>My link</a> <h1>My header</h1> </body> </html>
  • 10. Finding Element In HTML DOM Elements can be found by their “ID”, “Tag Name”, “Class Name”. “document.getElementById()” is used to find the element by their ids. “document.getElementsByTagName()” is used to find the element by the tag name.  Eg: document. getElementsByTagName(“header”); “document.getElementsByClassName()” is used to find the element by the class name.  Eg: document. getElementsByClassName(“logo”);
  • 11. Changing HTML HTML of any element can be modified by “innerHTML” property as follows: Value of any attribute of an element can also be changed as follows: <p id=“name"><strong>Hassan </strong></p> Hassan document.getElementById(“name”).innerHTML = ”<strong>Hassan</strong>” <p id=“name">Hassan</p> Hassan document.getElementById(“<img src=“abc.jpg” > name”).src= ”xyz.jpg” <img src=“xyz.jpg” >
  • 12. Changing CSS Style of any element can be modified by “style” property as follows: <p id=“name“ style=“color:blue”>Hassan</p> Hassan document.getElementById(“name”).style.color = ”blue” <p id=“name">Hassan</p> Hassan document.getElementById(id).style.property=new style
  • 13. Register Event Using HTML DOM Events can also be registered to any element using JavaScript HTML DOM as follows: document.getElementById("myBtn").onclick = function(){ //code to be executed. };