SlideShare a Scribd company logo
CS 299 – Web Programming and Design
Javascript Basics With
Coding Standards
CS 299 – Web Programming and Design
Introduction to JavaScript
What is JavaScript?
– It is designed to add interactivity to HTML pages
– It is a scripting language (a lightweight programming
language)
– It is an interpreted language (it executes without
preliminary compilation)
– Usually embedded directly into HTML pages
– And, Java and JavaScript are different
– Loosely typed language.
JavaScript is an object-based scripting language
which is lightweight and cross-platform
–
CS 299 – Web Programming and Design
What can a JavaScript Do?
• JavaScript gives HTML designers a programming tool:
– simple syntax
• JavaScript can put dynamic text into an HTML page
• JavaScript can react to events
• JavaScript can read and write HTML elements
• JavaScript can be used to validate data
• JavaScript can be used to detect the visitor’s browser
• JavaScript can be used to create cookies
– Store and retrieve information on the visitor’s computer
CS 299 – Web Programming and Design
JS How To & JS Where To
CS 299 – Web Programming and Design
JavaScript where to & How to
• The HTML <script> tag is used to insert a JavaScript into an
HTML page
<script type=“text/javascript”>
document.write(“Hello World!”)
</script>
• Ending statements with a semicolon?
– Optional; required when you want to put multiple statements on a
single line
• JavaScript can be inserted within the head, the body, or use
external JavaScript file
• How to handle older browsers?
<script type=“text/javascript”>
<!—
document.write(“Hello World!”)
// -->
</script>
CS 299 – Web Programming and Design
JavaScript Where To
• You can include JavaScripts in head, body, or
simply use external JavaScript file (.js)
• JavaScripts in the body section will be
executed while the page loads
• JavaScripts in the head section will be
executed when called
• Examples:
•
CS 299 – Web Programming and Design
JS Statements
CS 299 – Web Programming and Design
JS Statements
•

JavaScript statements are commands to the browser

JavaScript code is a sequence of statements

JavaScript statements are separated with semicolon

Multiple statement on one line is allowed

JavaScript statements can be grouped together in code
blocks

You can break a code line after an operator or a comma.

CS 299 – Web Programming and Design
JS Comments
CS 299 – Web Programming and Design
JavaScript Comments
Single-line Comment

Single line comments start with //.
Multi-line Comment

Multi-line comments start with /* and end with */.
CS 299 – Web Programming and Design
JS Variables
CS 299 – Web Programming and Design

JavaScript Variables

Variables are used to store data.

A variable is a "container" for information you
want to store. A variable's value can change
during the script. You can refer to a variable by
name to see its value or to change its value.

Rules for variable names:
 Variable names are case sensitive
 They must begin with a letter or the underscore
character

strname – STRNAME (not same)
CS 299 – Web Programming and Design

JavaScript Variables Declartion

Names can contain letters, digits, underscores, and dollar signs.

Names must begin with a letter

Names can also begin with $ and _

Names are case sensitive (y and Y are different variables)

Reserved words (like JavaScript keywords) cannot be used as
names

var x = 5;

var y = 6;

var z = x + y;
CS 299 – Web Programming and Design
.The scope of a variable is the region of your program in
which it is defined. JavaScript variables have only two
scopes.
Global Variables − A global variable has global scope
which means it can be defined anywhere in your
JavaScript code.
Local Variables − A local variable will be visible only
within a function where it is defined. Function parameters
are always local to that functionJavaScript allows you to
work with three primitive data types −
JavaScript Variable
Scope
CS 299 – Web Programming and Design
.Global variable Declartion:Ouside the Function
<script>
var value=50;//global variable
function a(){
alert(value);
}
function b(){
alert(value);
}
</script>
Global Variable Declaration:outside Function
CS 299 – Web Programming and Design
.Global Varible Declaration inside function:
function m(){
window.value=100;//declaring global variable by window
object
}
function n(){
alert(window.value);//accessing global variable from other
function
}
Global Variable Declaration:inside Function
CS 299 – Web Programming and Design
JS Operators
CS 299 – Web Programming and Design

JavadScript
Operators(Arithematic Operator)
Arithmetic Operators
Operator Description Example Result
+
x+y
Addition x=2 4
y=2
-
y=2
x-y
Subtraction x=5 3
*
y=4
x*y
Multiplication x=5 20
/
5/2
Division
2,5
15/5 3
%
10%8
10%2
Modulus (division
remainder)
2
0
5%2 1
CS 299 – Web Programming and Design

JavadScript
Operators(Arithematic Operator)
Arithmetic Operators
Operator Description Example Result
+
x+y
Addition x=2 4
y=2
-
y=2
x-y
Subtraction x=5 3
*
y=4
x*y
Multiplication x=5 20
/
5/2
Division
2,5
15/5 3
%
10%8
10%2
Modulus (division
remainder)
2
0
5%2 1
CS 299 – Web Programming and Design

Assignment Operators
Assignment Operators Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y
CS 299 – Web Programming and Design

Comparison Operators
Comparison Operators
Operator Description Example
== is equal to 5==8 returns false
===
x==y
return
s true
x===y
return
s false
is equal to (checks for
both value and
type)
x=5
y="5"
!= is not equal 5!=8 returns true
> is greater than 5>8 returns false
< is less than 5<8 returns true
>= is greater than or equal
to
5>=8 returns false
<= is less than or equal to 5<=8 returns true
CS 299 – Web Programming and Design

Logical Operators -
Logical Operators Operator Description Example
&&
(x < 10 && y > 1)
returns true
and x=6
y=3
||
y=3
(x==5 || y==5)
returns false
or x=6
!
y=3
!(x==y) returns
true
not x=6
CS 299 – Web Programming and Design
JS Comparisons
Control Structures
 There are three basic types of control
structures in JavaScript: the if statement,
the while loop, and the for loop
 Each control structure manipulates a block
of JavaScript expressions beginning with
{ and ending with }
CS 299 – Web Programming and Design

Conditional Statements
if statement
if...else statement
if...else if... statement.
CS 299 – Web Programming and Design

Loop Statements
While Statement
Do ... While statement
For statement.
CS 299 – Web Programming and Design

Loop Control Statements
Break Statement.
Continue Statement.
CS 299 – Web Programming and Design
JS Popup Boxes
CS 299 – Web Programming and Design

JavaScript Popup Boxes

Alert Box
 An alert box is often used if you want to make
sure information comes through to the user.
 When an alert box pops up, the user will have to
click "OK" to proceed.
<script>
alert("Hello World!")
</script>
CS 299 – Web Programming and Design

JavaScript Popup Boxes - 2

Confirm Box
 A confirm box is often used if you want the user
to verify or accept something.
 When a confirm box pops up, the user will have
to click either "OK" or "Cancel" to proceed.
 If the user clicks "OK", the box returns true. If
the user clicks "Cancel", the box returns false.
CS 299 – Web Programming and Design

JavaScript Popup Boxes - 3

Prompt Box
 A prompt box is often used if you want the user
to input a value before entering a page.
 When a prompt box pops up, the user will have
to click either "OK" or "Cancel" to proceed after
entering an input value.
 If the user clicks "OK“, the box returns the input
value. If the user clicks "Cancel“, the box
returns null.
CS 299 – Web Programming and Design

Prompt Box Example
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Alert</h2>
<button onclick="myFunction()">Try
it</button>
<script>
function myFunction() {
alert("I am an alert box!");
}
CS 299 – Web Programming and Design
JS Function
CS 299 – Web Programming and Design

function
<script type = "text/javascript">
<!--
function functionname(parameter-list) {
statements
}
//-->
</script>.
CS 299 – Web Programming and Design
JS Events
CS 299 – Web Programming and Design

Window.print()
<html>
<head>
<script type = "text/javascript">
<!--
//-->
</script>
</head>
<body>
<form>
<input type = "button" value = "Print" onclick = "window.print()" />
</form>
</body>
<html>.

More Related Content

What's hot

My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
Syed Irtaza Ali
 
Ddpz2613 topic6 frame
Ddpz2613 topic6 frameDdpz2613 topic6 frame
Ddpz2613 topic6 frame
Mohamad Sahiedan
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
Arash Manteghi
 
Html frames
Html framesHtml frames
Html frames
nobel mujuji
 
Haml. New HTML? (RU)
Haml. New HTML? (RU)Haml. New HTML? (RU)
Haml. New HTML? (RU)
Kirill Zonov
 
Introduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and JavascriptIntroduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and Javascript
Agustinus Theodorus
 
HTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - FronteersHTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - Fronteers
Robert Nyman
 
JavaScript Introduction and Implementation
JavaScript Introduction and ImplementationJavaScript Introduction and Implementation
JavaScript Introduction and Implementation
Maher Hossain
 
HTML Frameset & Inline Frame
HTML Frameset & Inline FrameHTML Frameset & Inline Frame
HTML Frameset & Inline Frame
Nisa Soomro
 
LESS CSS Pre-processor
LESS CSS Pre-processorLESS CSS Pre-processor
LESS CSS Pre-processor
Kannika Kong
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
ambuj pathak
 
Java Script
Java ScriptJava Script
Java Script
SURBHI SAROHA
 
Html frames
Html framesHtml frames
Html frames
eShikshak
 
syllabus
syllabussyllabus
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
Vaibhav Sinha
 
Html basics 8 frame
Html basics 8 frameHtml basics 8 frame
Html basics 8 frame
H K
 
Learn html and css from scratch
Learn html and css from scratchLearn html and css from scratch
Learn html and css from scratch
Mohd Manzoor Ahmed
 
Html 5 Forms
Html 5 FormsHtml 5 Forms
Html 5 Forms
Jim Gerland
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
syeda zoya mehdi
 
Web Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTMLWeb Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTML
Der Lo
 

What's hot (20)

My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 
Ddpz2613 topic6 frame
Ddpz2613 topic6 frameDdpz2613 topic6 frame
Ddpz2613 topic6 frame
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
 
Html frames
Html framesHtml frames
Html frames
 
Haml. New HTML? (RU)
Haml. New HTML? (RU)Haml. New HTML? (RU)
Haml. New HTML? (RU)
 
Introduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and JavascriptIntroduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and Javascript
 
HTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - FronteersHTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - Fronteers
 
JavaScript Introduction and Implementation
JavaScript Introduction and ImplementationJavaScript Introduction and Implementation
JavaScript Introduction and Implementation
 
HTML Frameset & Inline Frame
HTML Frameset & Inline FrameHTML Frameset & Inline Frame
HTML Frameset & Inline Frame
 
LESS CSS Pre-processor
LESS CSS Pre-processorLESS CSS Pre-processor
LESS CSS Pre-processor
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Java Script
Java ScriptJava Script
Java Script
 
Html frames
Html framesHtml frames
Html frames
 
syllabus
syllabussyllabus
syllabus
 
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 basics 8 frame
Html basics 8 frameHtml basics 8 frame
Html basics 8 frame
 
Learn html and css from scratch
Learn html and css from scratchLearn html and css from scratch
Learn html and css from scratch
 
Html 5 Forms
Html 5 FormsHtml 5 Forms
Html 5 Forms
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
 
Web Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTMLWeb Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTML
 

Similar to Java script

Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
SANTOSH RATH
 
Java scipt
Java sciptJava scipt
Java script
Java scriptJava script
Java script
Jay Patel
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
Mujtaba Haider
 
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
pkaviya
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
wildcat9335
 
Javascript
JavascriptJavascript
Javascript
Nital Shingala
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
Asanka Indrajith
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
Jaya Kumari
 
Java script
Java scriptJava script
Unit 2.4
Unit 2.4Unit 2.4
Java script
Java scriptJava script
Java script
Fajar Baskoro
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
rashmiisrani1
 
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
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
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
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Unit 2.4
Unit 2.4Unit 2.4
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu
 
Java script
Java scriptJava script
Java script
Ravinder Kamboj
 

Similar to Java script (20)

Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
 
Java scipt
Java sciptJava scipt
Java scipt
 
Java script
Java scriptJava script
Java script
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
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
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Java script
Java scriptJava script
Java script
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Java script
Java scriptJava script
Java script
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
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
 
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
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 
Java script
Java scriptJava script
Java script
 

More from Sanjay Gunjal

Unit01_Session_07.pdf
Unit01_Session_07.pdfUnit01_Session_07.pdf
Unit01_Session_07.pdf
Sanjay Gunjal
 
Unit01_Session_06.pdf
Unit01_Session_06.pdfUnit01_Session_06.pdf
Unit01_Session_06.pdf
Sanjay Gunjal
 
Unit01_Session_04.pdf
Unit01_Session_04.pdfUnit01_Session_04.pdf
Unit01_Session_04.pdf
Sanjay Gunjal
 
Unit01_Session_03.pptx
Unit01_Session_03.pptxUnit01_Session_03.pptx
Unit01_Session_03.pptx
Sanjay Gunjal
 
Unit01_Session_05.ppt
Unit01_Session_05.pptUnit01_Session_05.ppt
Unit01_Session_05.ppt
Sanjay Gunjal
 
Unit02_Session_02 .ppt
Unit02_Session_02 .pptUnit02_Session_02 .ppt
Unit02_Session_02 .ppt
Sanjay Gunjal
 
Unit01_Session_01 .pptx
Unit01_Session_01 .pptxUnit01_Session_01 .pptx
Unit01_Session_01 .pptx
Sanjay Gunjal
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
Sanjay Gunjal
 
java database connection (jdbc)
java database connection (jdbc)java database connection (jdbc)
java database connection (jdbc)
Sanjay Gunjal
 

More from Sanjay Gunjal (9)

Unit01_Session_07.pdf
Unit01_Session_07.pdfUnit01_Session_07.pdf
Unit01_Session_07.pdf
 
Unit01_Session_06.pdf
Unit01_Session_06.pdfUnit01_Session_06.pdf
Unit01_Session_06.pdf
 
Unit01_Session_04.pdf
Unit01_Session_04.pdfUnit01_Session_04.pdf
Unit01_Session_04.pdf
 
Unit01_Session_03.pptx
Unit01_Session_03.pptxUnit01_Session_03.pptx
Unit01_Session_03.pptx
 
Unit01_Session_05.ppt
Unit01_Session_05.pptUnit01_Session_05.ppt
Unit01_Session_05.ppt
 
Unit02_Session_02 .ppt
Unit02_Session_02 .pptUnit02_Session_02 .ppt
Unit02_Session_02 .ppt
 
Unit01_Session_01 .pptx
Unit01_Session_01 .pptxUnit01_Session_01 .pptx
Unit01_Session_01 .pptx
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
 
java database connection (jdbc)
java database connection (jdbc)java database connection (jdbc)
java database connection (jdbc)
 

Recently uploaded

GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 

Recently uploaded (20)

GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 

Java script

  • 1. CS 299 – Web Programming and Design Javascript Basics With Coding Standards
  • 2. CS 299 – Web Programming and Design Introduction to JavaScript What is JavaScript? – It is designed to add interactivity to HTML pages – It is a scripting language (a lightweight programming language) – It is an interpreted language (it executes without preliminary compilation) – Usually embedded directly into HTML pages – And, Java and JavaScript are different – Loosely typed language. JavaScript is an object-based scripting language which is lightweight and cross-platform –
  • 3. CS 299 – Web Programming and Design What can a JavaScript Do? • JavaScript gives HTML designers a programming tool: – simple syntax • JavaScript can put dynamic text into an HTML page • JavaScript can react to events • JavaScript can read and write HTML elements • JavaScript can be used to validate data • JavaScript can be used to detect the visitor’s browser • JavaScript can be used to create cookies – Store and retrieve information on the visitor’s computer
  • 4. CS 299 – Web Programming and Design JS How To & JS Where To
  • 5. CS 299 – Web Programming and Design JavaScript where to & How to • The HTML <script> tag is used to insert a JavaScript into an HTML page <script type=“text/javascript”> document.write(“Hello World!”) </script> • Ending statements with a semicolon? – Optional; required when you want to put multiple statements on a single line • JavaScript can be inserted within the head, the body, or use external JavaScript file • How to handle older browsers? <script type=“text/javascript”> <!— document.write(“Hello World!”) // --> </script>
  • 6. CS 299 – Web Programming and Design JavaScript Where To • You can include JavaScripts in head, body, or simply use external JavaScript file (.js) • JavaScripts in the body section will be executed while the page loads • JavaScripts in the head section will be executed when called • Examples: •
  • 7. CS 299 – Web Programming and Design JS Statements
  • 8. CS 299 – Web Programming and Design JS Statements •  JavaScript statements are commands to the browser  JavaScript code is a sequence of statements  JavaScript statements are separated with semicolon  Multiple statement on one line is allowed  JavaScript statements can be grouped together in code blocks  You can break a code line after an operator or a comma. 
  • 9. CS 299 – Web Programming and Design JS Comments
  • 10. CS 299 – Web Programming and Design JavaScript Comments Single-line Comment  Single line comments start with //. Multi-line Comment  Multi-line comments start with /* and end with */.
  • 11. CS 299 – Web Programming and Design JS Variables
  • 12. CS 299 – Web Programming and Design  JavaScript Variables  Variables are used to store data.  A variable is a "container" for information you want to store. A variable's value can change during the script. You can refer to a variable by name to see its value or to change its value.  Rules for variable names:  Variable names are case sensitive  They must begin with a letter or the underscore character  strname – STRNAME (not same)
  • 13. CS 299 – Web Programming and Design  JavaScript Variables Declartion  Names can contain letters, digits, underscores, and dollar signs.  Names must begin with a letter  Names can also begin with $ and _  Names are case sensitive (y and Y are different variables)  Reserved words (like JavaScript keywords) cannot be used as names  var x = 5;  var y = 6;  var z = x + y;
  • 14. CS 299 – Web Programming and Design .The scope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes. Global Variables − A global variable has global scope which means it can be defined anywhere in your JavaScript code. Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that functionJavaScript allows you to work with three primitive data types − JavaScript Variable Scope
  • 15. CS 299 – Web Programming and Design .Global variable Declartion:Ouside the Function <script> var value=50;//global variable function a(){ alert(value); } function b(){ alert(value); } </script> Global Variable Declaration:outside Function
  • 16. CS 299 – Web Programming and Design .Global Varible Declaration inside function: function m(){ window.value=100;//declaring global variable by window object } function n(){ alert(window.value);//accessing global variable from other function } Global Variable Declaration:inside Function
  • 17. CS 299 – Web Programming and Design JS Operators
  • 18. CS 299 – Web Programming and Design  JavadScript Operators(Arithematic Operator) Arithmetic Operators Operator Description Example Result + x+y Addition x=2 4 y=2 - y=2 x-y Subtraction x=5 3 * y=4 x*y Multiplication x=5 20 / 5/2 Division 2,5 15/5 3 % 10%8 10%2 Modulus (division remainder) 2 0 5%2 1
  • 19. CS 299 – Web Programming and Design  JavadScript Operators(Arithematic Operator) Arithmetic Operators Operator Description Example Result + x+y Addition x=2 4 y=2 - y=2 x-y Subtraction x=5 3 * y=4 x*y Multiplication x=5 20 / 5/2 Division 2,5 15/5 3 % 10%8 10%2 Modulus (division remainder) 2 0 5%2 1
  • 20. CS 299 – Web Programming and Design  Assignment Operators Assignment Operators Operator Example Is The Same As = x=y x=y += x+=y x=x+y -= x-=y x=x-y *= x*=y x=x*y /= x/=y x=x/y %= x%=y x=x%y
  • 21. CS 299 – Web Programming and Design  Comparison Operators Comparison Operators Operator Description Example == is equal to 5==8 returns false === x==y return s true x===y return s false is equal to (checks for both value and type) x=5 y="5" != is not equal 5!=8 returns true > is greater than 5>8 returns false < is less than 5<8 returns true >= is greater than or equal to 5>=8 returns false <= is less than or equal to 5<=8 returns true
  • 22. CS 299 – Web Programming and Design  Logical Operators - Logical Operators Operator Description Example && (x < 10 && y > 1) returns true and x=6 y=3 || y=3 (x==5 || y==5) returns false or x=6 ! y=3 !(x==y) returns true not x=6
  • 23. CS 299 – Web Programming and Design JS Comparisons
  • 24. Control Structures  There are three basic types of control structures in JavaScript: the if statement, the while loop, and the for loop  Each control structure manipulates a block of JavaScript expressions beginning with { and ending with }
  • 25. CS 299 – Web Programming and Design  Conditional Statements if statement if...else statement if...else if... statement.
  • 26. CS 299 – Web Programming and Design  Loop Statements While Statement Do ... While statement For statement.
  • 27. CS 299 – Web Programming and Design  Loop Control Statements Break Statement. Continue Statement.
  • 28. CS 299 – Web Programming and Design JS Popup Boxes
  • 29. CS 299 – Web Programming and Design  JavaScript Popup Boxes  Alert Box  An alert box is often used if you want to make sure information comes through to the user.  When an alert box pops up, the user will have to click "OK" to proceed. <script> alert("Hello World!") </script>
  • 30. CS 299 – Web Programming and Design  JavaScript Popup Boxes - 2  Confirm Box  A confirm box is often used if you want the user to verify or accept something.  When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.  If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
  • 31. CS 299 – Web Programming and Design  JavaScript Popup Boxes - 3  Prompt Box  A prompt box is often used if you want the user to input a value before entering a page.  When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.  If the user clicks "OK“, the box returns the input value. If the user clicks "Cancel“, the box returns null.
  • 32. CS 299 – Web Programming and Design  Prompt Box Example <!DOCTYPE html> <html> <body> <h2>JavaScript Alert</h2> <button onclick="myFunction()">Try it</button> <script> function myFunction() { alert("I am an alert box!"); }
  • 33. CS 299 – Web Programming and Design JS Function
  • 34. CS 299 – Web Programming and Design  function <script type = "text/javascript"> <!-- function functionname(parameter-list) { statements } //--> </script>.
  • 35. CS 299 – Web Programming and Design JS Events
  • 36. CS 299 – Web Programming and Design  Window.print() <html> <head> <script type = "text/javascript"> <!-- //--> </script> </head> <body> <form> <input type = "button" value = "Print" onclick = "window.print()" /> </form> </body> <html>.