SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
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. 
};

Mais conteúdo relacionado

Mais procurados

javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.pptsentayehu
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...Edureka!
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - IntroductionWebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...Edureka!
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 

Mais procurados (20)

javascript objects
javascript objectsjavascript objects
javascript objects
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 
Javascript
JavascriptJavascript
Javascript
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Html form tag
Html form tagHtml form tag
Html form tag
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Javascript
JavascriptJavascript
Javascript
 

Destaque

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
 

Destaque (12)

Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
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
 

Semelhante a Introduction to JavaScript Basics.

JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
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
 

Semelhante a Introduction to JavaScript Basics. (20)

JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
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
 

Último

eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainAbdul Ahad
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 

Último (20)

eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software Domain
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 

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. };