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

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

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