SlideShare a Scribd company logo
1 of 19
Session by,
Bonny Chacko
Nibodha Technologies
History
• JavaScript and Java are two completely different
languages, in both concept and design.
• Java (invented by Sun) is a more complex
programming language in the same category as C.

• ECMA-262 is the official name of the JavaScript
standard.
• JavaScript was invented by Brendan Eich.
• JavaScript is the scripting language of the Web.
Introduction
• All modern HTML pages are using JavaScript.
• A scripting language is a lightweight
programming language.
• JavaScript is programming code that can be
inserted into HTML pages.
• JavaScript code can be executed by all modern
web browsers.
Examples
• document.write("<h1>This is a heading</h1>");
(this will print the heading)
• button type="button" onclick="alert('Welcome!')">Click
Me!</button> .
(this will give an alert of welcome)
• You will often see document.getElementById("some id"). This
is defined in the HTML DOM.
• The DOM (Document Object Model) is the official W3C
standard for accessing HTML elements.
The <script> Tag
• The <script> and </script> tells where the
JavaScript starts and ends.
• If we put JavaScript code inside a function, we
can call that function when an event occurs.
• Scripts can be in the <body> or in the <head>
section of HTML or in both.
• Scripts can also be placed in external files.
• To use an external script, point to the .js file in
the "src" attribute of the <script> tag:
document.getElementById(id) method
• Used to access an HTML element from JavaScript
• Use the "id" attribute to identify the HTML element
• Eg:<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p id="demo">My First Paragraph</p>
<script>
document.getElementById("demo").innerHTML="My First JavaScript";
</script>
</body>
</html>
Points to ponder
• JavaScript is case sensitive.
Eg: A function getElementById is not the same as getElementbyID.
• You can break up a code line within a text string with a backslash.
Eg:document.write("Hello 
World!");
•
•
•
•

Comments can be added to explain the JavaScript
Single line comments start with //
Multi line comments start with /* and end with */.
Using Comments at the End of a Line
Eg:var x=5; // declare x and assign 5 to it
Variables
Consider , x=5,y=6,z=x+y
• In JavaScript these letters are called variables.
• Variable names must begin with a letter
• Variable names can also begin with $ and _ (but we will not
use it)
• Variable names are case sensitive (y and Y are different
variables)
• Declare variables with the var keyword
Eg: var carname;
• You can also assign a value to the variable when you
declare it:
Eg: var carname="Volvo";
Data tpyes
• JavaScript support Strings, Eg: “John Doe”
• JavaScript support numbers, Eg:var x1=34.00;
• It supports booleans, Eg:var x=true;
var y=false;
• JavaScript also supports Arrays
Eg: var cars=new Array();
cars[0]="Saab";
cars[1]="Volvo";
cars[2]="BMW“;
• Eg: condensed arrays,
var cars=new Array("Saab","Volvo","BMW");
Objects
• JavaScript supports Objects, an object is
delimited by curly braces.
• var person={firstname : "John",lastname : "Doe",
Id : 5566 };
• Objects are just data, with properties and
methods.
Properties are values associated with objects.
Methods are actions that objects can perform.
Creating Objects
• This example creates an object called "person",
and adds four properties to it:
• person=new Object();
person.firstname="John";
person.lastname="Doe";
person.age=50;
person.eyecolor="blue";
• We can also add new properties and methods to
already existing objects using syntax
objectName.propertyName
objectName.methodName()
• objectName.propertyName
This code uses the length property of the String
object to find the length of a string:
Eg: var message="Hello World!";
var x=message.length;
• objectName.methodName()
This example uses the toUpperCase() method of
the String object, to convert a text to uppercase:
Eg:var message="Hello world!";
var x=message.toUpperCase();
Functions
• A function is a block of code that will be executed
when "someone" calls it:
JavaScript Function Syntax:
• A function is written as a code block (inside curly
{ } braces), preceded by the function keyword:
• function functionname()
{
some code to be executed
}
Functions contd
• When you call a function, you can pass along some values
to it, these values are called arguments or parameters.
Eg: myFunction(argument1,argument2)
<button onclick="myFunction('Harry Potter','Wizard')">Try
it</button>
<script>
function myFunction(name,job)
{
alert("Welcome " + name + ", the " + job);
}
</script>
Function cont
Functions With a Return Value
• When using the return statement, the function
will stop executing, and return the specified
value.
Syntax
• function myFunction()
{
var x=5;
return x;
}
Scope of variables
Local JavaScript Variables
• A variable declared (using var) within a JavaScript
function becomes LOCAL and can only be accessed
from within that function. (the variable has local
scope).
• You can have local variables with the same name in
different functions, because local variables are only
recognized by the function in which they are declared.
Global JavaScript Variables
• Variables declared outside a function,
become GLOBAL, and all scripts and functions on the
web page can access it.(the variable has global scope)
Lifetime of JavaScript Variables
• The lifetime of JavaScript variables starts when they are
declared.
• Local variables are deleted when the function is completed.
• Global variables are deleted when you close the page.
Note:
• If you assign a value to a variable that has not yet been
declared, the variable will automatically be declared as
a GLOBALvariable.
Eg: carname="Volvo";
will declare the variable carname as a global variable , even
if it is executed inside a function
Will continue with…
•
•
•
•
•
•
•
•
•

JS Operators
JS Comparisons
JS Conditions
JS Switch
JS Loop For
JS Loop While
JS Breaks
JS Errors
JS Validation
THANK YOU

More Related Content

What's hot (20)

Generics
GenericsGenerics
Generics
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JS - Basics
JS - BasicsJS - Basics
JS - Basics
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
70 536
70 53670 536
70 536
 
Typescript
TypescriptTypescript
Typescript
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Java script
Java scriptJava script
Java script
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Javascript
JavascriptJavascript
Javascript
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Introduction To JavaScript
Introduction To JavaScriptIntroduction To JavaScript
Introduction To JavaScript
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
WEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScriptWEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScript
 
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 basics
Javascript basicsJavascript basics
Javascript basics
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
 

Viewers also liked

Learn CSS From Scratch
Learn CSS From ScratchLearn CSS From Scratch
Learn CSS From Scratchecobold
 
JavaScript Basics And DOM Manipulation
JavaScript Basics And DOM ManipulationJavaScript Basics And DOM Manipulation
JavaScript Basics And DOM ManipulationSiarhei Barysiuk
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
Adobe Photoshop Basics - Session 2
Adobe Photoshop Basics - Session 2Adobe Photoshop Basics - Session 2
Adobe Photoshop Basics - Session 2xneptune
 
Basic Photoshop Tutorial
Basic Photoshop TutorialBasic Photoshop Tutorial
Basic Photoshop TutorialMarc Dy
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet pptabhilashagupta
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Adobe Photoshop Basics - Session 1
Adobe Photoshop Basics - Session 1Adobe Photoshop Basics - Session 1
Adobe Photoshop Basics - Session 1xneptune
 
Adobe photoshop cs6 basic tutorials presentation
Adobe photoshop cs6 basic tutorials   presentationAdobe photoshop cs6 basic tutorials   presentation
Adobe photoshop cs6 basic tutorials presentationRishi Shah
 

Viewers also liked (15)

JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Learn CSS From Scratch
Learn CSS From ScratchLearn CSS From Scratch
Learn CSS From Scratch
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Css Basics
Css BasicsCss Basics
Css Basics
 
Basic css-tutorial
Basic css-tutorialBasic css-tutorial
Basic css-tutorial
 
JavaScript Basics And DOM Manipulation
JavaScript Basics And DOM ManipulationJavaScript Basics And DOM Manipulation
JavaScript Basics And DOM Manipulation
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
 
Adobe Photoshop Basics - Session 2
Adobe Photoshop Basics - Session 2Adobe Photoshop Basics - Session 2
Adobe Photoshop Basics - Session 2
 
Basic Photoshop Tutorial
Basic Photoshop TutorialBasic Photoshop Tutorial
Basic Photoshop Tutorial
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Adobe Photoshop Basics - Session 1
Adobe Photoshop Basics - Session 1Adobe Photoshop Basics - Session 1
Adobe Photoshop Basics - Session 1
 
Adobe photoshop cs6 basic tutorials presentation
Adobe photoshop cs6 basic tutorials   presentationAdobe photoshop cs6 basic tutorials   presentation
Adobe photoshop cs6 basic tutorials presentation
 

Similar to Javascript Basics by Bonny

Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOMSukrit Gupta
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxsandeshshahapur
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptxAlkanthiSomesh
 
BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptxMattMarino13
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONSyed Moosa Kaleem
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptDan Phiffer
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdfwildcat9335
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptxMattMarino13
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptxMattMarino13
 
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
 

Similar to Javascript Basics by Bonny (20)

Java script
Java scriptJava script
Java script
 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
 
Java script
Java scriptJava script
Java script
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
Java script
Java scriptJava script
Java script
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Javascript
JavascriptJavascript
Javascript
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
 
BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptx
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptx
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptx
 
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
 

Recently uploaded

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
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
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 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
 

Javascript Basics by Bonny

  • 2. History • JavaScript and Java are two completely different languages, in both concept and design. • Java (invented by Sun) is a more complex programming language in the same category as C. • ECMA-262 is the official name of the JavaScript standard. • JavaScript was invented by Brendan Eich. • JavaScript is the scripting language of the Web.
  • 3. Introduction • All modern HTML pages are using JavaScript. • A scripting language is a lightweight programming language. • JavaScript is programming code that can be inserted into HTML pages. • JavaScript code can be executed by all modern web browsers.
  • 4. Examples • document.write("<h1>This is a heading</h1>"); (this will print the heading) • button type="button" onclick="alert('Welcome!')">Click Me!</button> . (this will give an alert of welcome) • You will often see document.getElementById("some id"). This is defined in the HTML DOM. • The DOM (Document Object Model) is the official W3C standard for accessing HTML elements.
  • 5. The <script> Tag • The <script> and </script> tells where the JavaScript starts and ends. • If we put JavaScript code inside a function, we can call that function when an event occurs. • Scripts can be in the <body> or in the <head> section of HTML or in both. • Scripts can also be placed in external files. • To use an external script, point to the .js file in the "src" attribute of the <script> tag:
  • 6. document.getElementById(id) method • Used to access an HTML element from JavaScript • Use the "id" attribute to identify the HTML element • Eg:<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p id="demo">My First Paragraph</p> <script> document.getElementById("demo").innerHTML="My First JavaScript"; </script> </body> </html>
  • 7. Points to ponder • JavaScript is case sensitive. Eg: A function getElementById is not the same as getElementbyID. • You can break up a code line within a text string with a backslash. Eg:document.write("Hello World!"); • • • • Comments can be added to explain the JavaScript Single line comments start with // Multi line comments start with /* and end with */. Using Comments at the End of a Line Eg:var x=5; // declare x and assign 5 to it
  • 8. Variables Consider , x=5,y=6,z=x+y • In JavaScript these letters are called variables. • Variable names must begin with a letter • Variable names can also begin with $ and _ (but we will not use it) • Variable names are case sensitive (y and Y are different variables) • Declare variables with the var keyword Eg: var carname; • You can also assign a value to the variable when you declare it: Eg: var carname="Volvo";
  • 9. Data tpyes • JavaScript support Strings, Eg: “John Doe” • JavaScript support numbers, Eg:var x1=34.00; • It supports booleans, Eg:var x=true; var y=false; • JavaScript also supports Arrays Eg: var cars=new Array(); cars[0]="Saab"; cars[1]="Volvo"; cars[2]="BMW“; • Eg: condensed arrays, var cars=new Array("Saab","Volvo","BMW");
  • 10. Objects • JavaScript supports Objects, an object is delimited by curly braces. • var person={firstname : "John",lastname : "Doe", Id : 5566 }; • Objects are just data, with properties and methods. Properties are values associated with objects. Methods are actions that objects can perform.
  • 11. Creating Objects • This example creates an object called "person", and adds four properties to it: • person=new Object(); person.firstname="John"; person.lastname="Doe"; person.age=50; person.eyecolor="blue"; • We can also add new properties and methods to already existing objects using syntax objectName.propertyName objectName.methodName()
  • 12. • objectName.propertyName This code uses the length property of the String object to find the length of a string: Eg: var message="Hello World!"; var x=message.length; • objectName.methodName() This example uses the toUpperCase() method of the String object, to convert a text to uppercase: Eg:var message="Hello world!"; var x=message.toUpperCase();
  • 13. Functions • A function is a block of code that will be executed when "someone" calls it: JavaScript Function Syntax: • A function is written as a code block (inside curly { } braces), preceded by the function keyword: • function functionname() { some code to be executed }
  • 14. Functions contd • When you call a function, you can pass along some values to it, these values are called arguments or parameters. Eg: myFunction(argument1,argument2) <button onclick="myFunction('Harry Potter','Wizard')">Try it</button> <script> function myFunction(name,job) { alert("Welcome " + name + ", the " + job); } </script>
  • 15. Function cont Functions With a Return Value • When using the return statement, the function will stop executing, and return the specified value. Syntax • function myFunction() { var x=5; return x; }
  • 16. Scope of variables Local JavaScript Variables • A variable declared (using var) within a JavaScript function becomes LOCAL and can only be accessed from within that function. (the variable has local scope). • You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared. Global JavaScript Variables • Variables declared outside a function, become GLOBAL, and all scripts and functions on the web page can access it.(the variable has global scope)
  • 17. Lifetime of JavaScript Variables • The lifetime of JavaScript variables starts when they are declared. • Local variables are deleted when the function is completed. • Global variables are deleted when you close the page. Note: • If you assign a value to a variable that has not yet been declared, the variable will automatically be declared as a GLOBALvariable. Eg: carname="Volvo"; will declare the variable carname as a global variable , even if it is executed inside a function
  • 18. Will continue with… • • • • • • • • • JS Operators JS Comparisons JS Conditions JS Switch JS Loop For JS Loop While JS Breaks JS Errors JS Validation