SlideShare a Scribd company logo
JavaScript language 
fundamentals 
Learning Objectives 
Brief history of JavaScript 
Uses 
Language features 
Inclusion of script in HTML 
<noscript> and hiding scripts 
Scripts inside <body> and <head> 
External scripts
Brief history of JavaScript 
Netscape developed a scripting language called LiveScript 
Supported both client side and server side scripting 
Netscape Navigator 2 
(support for java applets and LiveScript 
renamed as JavaScript1.1) 
Microsoft- JScript IE 3 
1997 ECMA (European 
Computer Manufacturers 
Association) 
Standardized ECMA script 
Opera 
supporting 
JavaScript 1.1 
W3C standardized DOM to access HTML and XML 
JavaScript 1.2
Response 
HTML file 
JAVA 
SCRIPT 
Request 
Servlet files 
JSP files 
HTML files 
Client Web Server 
Script 
executes 
locally and 
interacts with 
the browser 
Programs 
executes on the 
server and sends 
the response
Uses 
• To create more interactive pages- client side validations etc. 
• To generate html dynamically. 
• Event handling 
• To enhance browser capabilities by giving it a better look – printing 
on status bar etc. 
• Interaction with embedded components like applets and active x 
controls. 
Language Features 
• Object based language:no object inheritance and subclassing. Object 
-based because it depends on built-in objects to function. 
• Semicolon, as separator for multiple statements in the same line. 
• Syntax similar to c++ and java 
• Case sensitive 
• Loosely typed 
• Platform independent 
• Interpreted
Scripts in HTML 
<HTML><HEAD><TITLE>Hello</TITLE></HEAD> 
<BODY> 
First java script code<br> 
<SCRIPT> 
//Java script single line comment 
document.write(“Hello java script”) 
/* java script script 
multi-line comment */ 
</SCRIPT></BODY></HTML> 
NOSCRIPT and hiding scripts 
Some browser don’t support javascript. They will display the javascript on the 
web page since they cannot interpret. To avoid that the script need to be 
commented. Also for such browsers <NOSCRIPT> tag may be used which 
can display alternative text for scripts. 
<SCRIPT> 
<!— 
document.write(“Hello java script”) 
--> 
</SCRIPT> 
<NOSCRIPT>Java script is not supported</NOSCRIPT>
External Script 
<HTML> 
<HEAD> 
<BODY> 
<SCRIPT LANGUAGE=“JavaScript” 
SRC=“JSfile.js”> 
</SCRIPT> 
</BODY> 
</HTML> 
JSfile.js 
document.write(“Hello”) 
Scripts inside body and head 
Inside head only declarations should be done. No write 
statements must appear inside head tag. 
<HTML><HEAD><TITLE>Hello</TITLE> 
<SCRIPT> 
document.write(“Hello java script”) 
</SCRIPT> 
</HEAD> 
<BODY></BODY> 
</HTML> 
Incorrect
Nuts and Bolts 
Learning Objectives 
Variables and datatypes 
Conversion 
Operators 
Control statements 
Arrays 
Functions
Variables and Datatypes 
• Variable names must begin with a letter, under-score or $., 
subsequent characters can be letter or number. 
• Variables need not be declared in JavaScript. They just need to 
be assigned with proper data. They are called data stores. 
• Data types supported by Java Script are 
a) Numeric – integer and floating point numbers (64 bit, IEE754 
floating point) 
b) Strings 
c) Boolean- true, false 
d) Null, Undefined and NaN 
<HTML><HEAD><SCRIPT LANGUAGE=“JavaScript” > 
$I=“hello” 
</SCRIPT></HEAD> 
<BODY><SCRIPT LANGUAGE=“JavaScript”> 
document.write($I) 
</script> 
</body>
Conversion: parseInt() and parseFloat() 
Operators 
Arithmetic: + - * / % += -= *= /= %= 
Logical: & | ! && || 
Relational: > >= < <= == != 
String concatenation: + 
Bit wise: >> << >>> >>= <<= >>>= 
Mixing up datatypes: 
S=“abc” 
I=123 
document.write(S+I)  abc123 
S=“abc” 
B=true 
document.write(S+B)  abctrue 
B=true 
I=123 
document.write(B+1)  124
Control statements 
• Same as in c++ or java 
• if else 
• for 
• while 
• do .. while 
• switch 
<HTML><HEAD><SCRIPT LANGUAGE=“JavaScript” > 
</SCRIPT></HEAD> 
<BODY><SCRIPT LANGUAGE=“JavaScript”> 
i=15 
b=true 
for(j=2;j<=i/2;j++){ 
if(i%j==0){ 
b=false; 
break;} 
} 
if(b) document.write(i + “ is a prime number”) 
else document.write(i + “ is not a prime number”)</script> 
</body></html>
Arrays • Declaration: are objects in JavaScript 
a= new Array(3) 
a[0]=1 a[1]=2 a[2]=3 
• A single array can hold any kind of data 
junk= new Array(3) 
junk[0]=“Sunday” junk[1]=0 junk[2]=true 
• Array length 
a.length 
• Array size is incremented dynamically 
a= new Array() 
a[4]=4 
a.length is 5 
• Initialized array 
week=new Array(“sun”,”mon”,”tue”,”wed”,”thu”,”fri”,”sat”) 
document.write(week[0]) sun 
document.write(week) sun, mon, tue, wed … 
• Array of array: matrix= new Array(new Array(1,2,3), new Array(4,5,6) 
a[0][1] 2
Function • Creation 
<html> 
<head> 
<script language=“JavaScript”> 
<!-- 
function display(x){ 
document.write(x)} 
--> 
</script> 
</head> 
<body> 
<script> 
<!— 
display(“hello”) 
--> 
</script> 
</body> 
</html> 
• Function with return values 
<html><head> 
<script language=“JavaScript”> 
<!-- 
function isNumber(x){ 
for(i=0;i<x.length;i++){ 
if(x.charAt(i)<‘0’ || x.charAt(i)>’9’) 
return false 
}r 
eturn true } 
--> 
</script></head><body> 
<script> 
<!— 
if(isNumber(“123”) 
document.write(“number”) 
else 
document.write(“not a number”) 
--></script></body></html>
•Calling a function 
function display(x){ 
if(x==null) 
x=“Greetings” 
document.write(x) } 
Can be called as : display() or display(“hello”) 
No overloading possible. If overloaded functions are provided, only the last 
function is considered 
•Function arguments: arguments array can be used to collect the arguments 
of a function. 
<script language=“JavaScript”> 
<!-- 
function sum(){ 
total=0 
for(j=0;j<sum.arguments.length;j++){ 
total+=sum.arguments[j]; 
document.write(sum)} 
--></script>
•Local and Global variables 
Local variables are created using var 
<!-- 
function sum(){ 
total=0  var total=0 then it is available only in the function 
for(j=0;j<sum.arguments.length;j++){ 
total+=sum.arguments[j]; 
} 
--></script> 
…< 
script> 
<!— 
document.write(total) // ok doesn't display if local variable 
--> 
</script>
JavaScript Object Model, 
window object 
Learning Objectives 
Object Model 
window object 
properties 
methods 
events 
Example communicating with the user 
Example displaying status bar messages on window events 
Example working with timer
JavaScript Object Model 
• Also called DOM (document object model) or web 
browser object model. 
• JavaScript interacts with the web browser using the 
objects defined in the Object model. 
windowdocument  link 
history anchor 
location image 
frames formbutton, text, 
password,radio, 
checkbox, select 
submit, reset, hidden 
Array, String, Date, Math
window object 
•window is the default object that is available to the JavaScript. 
•document.write  document is an object inside window and instead 
of document.write we can also write window.document.write implying 
write on current window’s document. 
•Properties: 
name, self, top, parent, opener, defaultStatus, status, closed, length 
Methods: alert(displayString), String prompt(question,defaultanswer), 
boolean confirm(question), Timer setTimeOut(expression, millsecs), 
clearTimeOut(timerobj), blur(), focus(), open(url,name,[options]), 
close() 
Events: onLoad, onUnload, onFocus, onBlur, OnError 
[options]: menubar=,toolbar,status, width=, height=
Communicating with user 
<html><head> 
<script> 
function communicate(){ 
alert(“Hello”) 
s=prompt(“What is your name”, “xyz”) 
b=confirm(“Do you want to see your name displayed in colors”) 
a=new Array(“RED”,”GREEN”,”BLUE”,”YELLOW”, “BLACK”,”PURPLE) 
while(b){ 
document.write(“<font color=“+a[i]+”>”+s+”</font>”) 
if(i++>a.length)i=0 
b=confirm(“Do you want to continue”)}} 
</script> 
</head><body onUnload=“alert(‘Bye!’)”> 
<script> communicate()</script> 
</body></html>
status bar and window events 
<html><head> 
<script> 
function setStatus(x){ 
status=x 
} 
</script> 
</head> 
<body onLoad=“defaultStatus=‘welcome’” 
onBlur=“setStatus(‘OUT’) onFocus=“setStatus(“ON”)> 
Look at the status bar 
</body> 
</html>
Timer 
<html><head> 
<script> 
a=new Array(“Welcome”,”to”,”jis”) 
i=0 
function setTimer(){ 
setTimeout(“display()”,1000); 
} 
function display(){ 
status=a[i] 
i=i++%3 
setTimer() 
}
open() 
<html> 
<head> 
<title>win4</title> 
</head> 
<body onLoad="open('win2.html','x' ,'menubar=0')"> 
1. HTTP is a ______________ protocol<br> 
a) application layer<br> 
b) session layer<br> 
c) transport layer<br> 
d) network layer 
</body> 
</html>
location, frames, history, 
Opening a new page on top window
location 
<html><head> 
</head> 
<body> 
<form> 
<input type=button onCLick=“location.href=‘x.html’”> 
</form> 
</body> 
</html> 
Properties: 
href, port,path, pathname
<html><head> 
<title>Shop with us</title> 
<script> 
function display(x){ 
switch(x){ 
case 'left': 
parent.b.l.location.href="img.jpg" 
break 
case 'right': 
parent.b.frames[1].location.href="img.jpg" 
break 
case 'top': 
top.location.href="img.jpg" 
break 
case 'bottom' : 
parent.b.location.href="img.jpg" 
break 
case 'self' : 
location.href="img.jpg" 
break 
default: 
location.href=history.back() 
}} 
</script></head>
<body> 
<form> 
<input type="button" value="Left" onClick="display('left')"> 
<input type="button" value="Right" onClick="display('right')"> 
<input type="button" value="Top" onClick="display('top')"> 
<input type="button" value="Bottom" onClick="display('bottom')"> 
<input type="button" value="self" onClick="display('self')"> 
<input type="button" value="back" onClick="display('xx')"> 
</form> 
</body> 
</html>
document 
Properties: images[], forms[], links[], anchors[],bgColor, fgColor, 
title, linkColor, alinkColor, vlinkColor 
Methods: open([mimetype]), write(expr1), close() 
Example 1:bgColor and fgColor 
<body onFocus=“bgColor=‘white’;fgColor=‘black’” 
onBlur=“bgColor=‘black’;fgColor=‘black’”> 
Example 2:Generating a document 
<html><head><script> 
function generate(){ 
win=open("","gen") 
win.document.open("texthtml") 
win.document.write("<html><body onLoad=alert('ok')><U>Welcome</U>") 
win.document.write("</body></html>") 
win.document.close() } 
</script> 
<body><form><input type=‘button’ onClick=‘generate()’></form></body> 
</html>
images 
Properties:border, height, width, src, name, complete 
Creating new Image object: 
im=new Image() 
im=new Image(40,50) 
Events: 
onLoad, onError, onAbort, onMouseOver, onMouseOut, onDblClick 
Example 1: 
<html><head> 
<script> 
i=0 
imgs=new 
Array("image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg") 
function change(){ 
document.images[0].src=imgs[i++ % imgs.length]} 
</script></head> 
<body><img src="image5.jpg" onMouseOver="change()"> 
</body> 
</html>
On the internet it takes time to download the image. So to check if the 
image has been downloaded and do the required we need image as object. 
<script> 
i=0 
imgs=new Array(5) 
for(i=0;i<5;i++){ 
imgs[i]=new Image() 
imgs[i].src="image"+ (i+1)+".jpg“ } 
i=0 
function set(){ setTimeout('change()',1000) } 
function change(){ 
if(imgs[i].complete){ 
document.images[0].src=imgs[i++ % imgs.length].src 
set()}} 
</script> 
</head> 
<body><img src="image5.jpg"> 
<script>set()</script></body></html>
form 
Properties: action, method, name, elements[], target 
Events: onSubmit, onReset 
Form elements: 
Events:All form elements: onBlur, onFocus 
Select,text, textarea: onChange 
Text, texrarea: onSelect 
Button,submit,reset,radio,checkbox: onClick 
Button: onMouseDown, onMouseUp, 
TextArea: onKeyDown, onKeyUp, onKeyPress 
Properties: 
All : name, type, value (except select) 
radio, checkbox: checked, defaultChecked 
select: length, options[], selectedIndex 
text, password, textarea:defaultValue 
Methods: 
All form elements: focus(), blur() 
button,submit, reset: click()
Example 1: Working with text, radio and checkbox 
<html><head><title>Validate</title><script> 
<!-- 
function check(){ 
with(document.forms[0]){ 
if ((name.value=="") ){ 
alert("Please ensure that all fields are filled up") 
return false } 
if(like[0].checked) 
s= "Thankyou, "+name.value +"." 
else 
s="Sorry !" 
s=s+" As per your suggestion we shall look into areas:("; 
for(i=0;i<better.length;i++) 
if (better[i].checked) 
s=s+ better[i].value+"," 
s=s+" and more ) for further improvements " } 
alert(s) 
return true}
//--> 
</script> 
</head><body> 
<form action="Frame.html" onSubmit="return check()"> 
Name: <input type=text name=name><br><br> 
Do you like our site 
<input type=radio name="like" checked>Yes 
<input type=radio name="like" >No<br><br> 
Tell us how we can make this site better for you:<br> 
<input type=checkbox name="better" value="Change bgcolor">Change the bg 
color<br> 
<input type=checkbox name="better" value="Change fgcolor">Change the fg 
color<br> 
<input type=checkbox name="better" value="Change layout">Change the 
layout<br> 
<input type=checkbox name="better" value="More services">Include more 
services<br><br> 
<input type=submit></form> 
</body> 
</html>
Example 2: Working with select 
<html><head><script> 
<!-- 
function check(){ 
i=document.f1.choose.options.selectedIndex; 
if(i!=0){ if(i==1) 
alert("Correct"); 
else 
alert("Your choice, "+ document.f1.choose.options[i].text +"- is 
incorrect"); 
}} 
//--> 
</script></head> 
<body> 
<form name=f1> 
Which of the following is not true about JavaScript? 
<select name="choose" onChange="check()">
<option>-------Select the best answer--------</option> 
<option>JavaScript is object-oriented language</option> 
<option>JavaScript is loosely typed language</option> 
<option>JavaScript is used for client side validations</option> 
<option>JavaScript is platform independent</option> 
</select> 
</form> 
</body> 
</html>
link, anchor and history 
links, anchors: array 
properties: href, hostname, pathname, port, target, protocol 
Events: onClick, onDblClick, onKeyDown, onKeyUp, onKeyPress, 
onMouseDown, onMouseUp, onMouseOver, onMouseOut 
Example: Game 
<html><head> 
<script> 
arr=new Array(‘one.hif’,’two.gif’) 
i=0 
im=“” 
function f(x){ 
r=Math.floor(Math.random()*2) 
document.images[x].src=arr[r] 
if(i==0) im=arr[r] 
if(i++>0 && im==arr[r]) 
alert(“You have won in “+ i + “ attempts”) 
} 
</script>
<body> 
<table><tr> 
<td><a href=“#” onClick=f(1)><img src=“blank.gif”></a></td> 
<td><a href=“#” onClick=f(2)><img src=“blank.gif”></a></td></tr> 
<td><a href=“#” onClick=f(3)><img src=“blank.gif”></a></td> 
<td><a href=“#” onClick=f(4)><img src=“blank.gif”></a></td></tr> 
</table> 
</body> 
</html> 
History 
Property: length 
Methods: 
back() 
forward() 
go(x)
Math 
Properties: PI, E 
Methods: sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), 
round(x), floor(x), ceil(x), max(x,y), min(x,y), sqrt(x), pow(x,y), 
random(), log(x) 
Rounding: 
with(Math){ 
X=floor(3.5)  3 
Y=ceil(3.5)4 
Z=round(3.5) 4 
} 
r=Math.floor(Math.random()*2) 
r between 0 and 1.
Date object var dt= new Date(); 
Creates a new date object which contains system’s current date and 
time. 
Methods: 
getDate() getMonth() getYear() 
getHours() getMinutes() getSeconds() 
setDate(value) setMonth(value) 
setYear(value) setHours(value) 
setMinutes(value) setSeconds(value) 
toGMTString() toLocalString() 
Example 1: 
<html><head><title>time</title><script> 
<!-- 
function setTime() 
{ 
dt= new Date(); 
str=dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds(); 
document.forms[0].time.value=str; 
timer=setTimeout("setTime()",1000); 
} 
</script>
</head> 
<body><form> 
<input type=text name="time" readonly size=6> 
</form> 
<script>setTime()</script> 
</body></html> 
Example 2: 
Difference between two dates: 
<script> 
Function diff(){ 
dt1=new Date(); 
dt2=new Date(2005,8,5) 
millsec=1000*60*60*24 
Days=Math.round((dt1-dt2)/millsec) 
alert(“no of days “+ days) 
}
String object 
Method Example HTML 
anchor(aname) “Part2”.anchor(“p2”) <a name=“p2”>Part2</a> 
big() “Welcome”.big() <BIG>Welcome</BIG> 
blink() “Highlights”.blink() <BLINK>Highlights</BLINK> 
bold() “Hello”.bold() <B>Hello</B> 
italics() “sky”.italics() <I>Sky</I> 
link(url) Yahoo.link( 
www.yahoo.com) 
<a href=www.yahoo.com> 
Yahoo</a> 
small() “Rights 
reserved”.small() 
<small>Rights 
reserver</small> 
strike() “strike”.strike() <strike>strike</strike> 
sub() “h”+”2”.sub()+ “o” h <SUB>2</SUB>o 
sup() “E=MC”+”2”.sup() E=MC<SUP>2</SUP>
Methods Examples Results 
toLowerCase() “Hi”.toLowerCase() hi 
toUpperCase() “hi”.toUpperCase() HI 
length “hi”.length 2 
indexOf(searchText, 
“hello.indexOf(“e”,0) 1 
startposition) 
substring(startpos, 
endpos) 
“hello”.substring(1,3) el 
charAt(indexPos) “hello”.charAt(4) O

More Related Content

PPTX
Java script
Jay Patel
 
PPTX
Java script
Shyam Khant
 
PPTX
Java script
Sadeek Mohammed
 
PPT
Java script final presentation
Adhoura Academy
 
PPT
Java script -23jan2015
Sasidhar Kothuru
 
PPTX
Java script basics
Shrivardhan Limbkar
 
PPTX
Java script
Rajkiran Mummadi
 
PPTX
Javascript
Nagarajan
 
Java script
Jay Patel
 
Java script
Shyam Khant
 
Java script
Sadeek Mohammed
 
Java script final presentation
Adhoura Academy
 
Java script -23jan2015
Sasidhar Kothuru
 
Java script basics
Shrivardhan Limbkar
 
Java script
Rajkiran Mummadi
 
Javascript
Nagarajan
 

What's hot (20)

PDF
Javascript
Aditya Gaur
 
PPT
Html JavaScript and CSS
Radhe Krishna Rajan
 
PPTX
Java script Session No 1
Saif Ullah Dar
 
PPTX
1. java script language fundamentals
Rajiv Gupta
 
PPT
Java Script ppt
Priya Goyal
 
PDF
8 introduction to_java_script
Vijay Kalyan
 
PPT
A quick guide to Css and java script
AVINASH KUMAR
 
PPTX
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
PPTX
Java script
Abhishek Kesharwani
 
PDF
Basic JavaScript Tutorial
DHTMLExtreme
 
PPTX
Introduction to java script
DivyaKS12
 
PPTX
Java Script An Introduction By HWA
Emma Wood
 
PPT
Java script Learn Easy
prince Loffar
 
PDF
Javascript
Rajavel Dhandabani
 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
PPT
Introduction to JavaScript
Andres Baravalle
 
DOCX
Javascript tutorial
Abhishek Kesharwani
 
PPTX
Javascript
D V BHASKAR REDDY
 
PPT
Javascript by geetanjali
Geetanjali Bhosale
 
PDF
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Javascript
Aditya Gaur
 
Html JavaScript and CSS
Radhe Krishna Rajan
 
Java script Session No 1
Saif Ullah Dar
 
1. java script language fundamentals
Rajiv Gupta
 
Java Script ppt
Priya Goyal
 
8 introduction to_java_script
Vijay Kalyan
 
A quick guide to Css and java script
AVINASH KUMAR
 
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Java script
Abhishek Kesharwani
 
Basic JavaScript Tutorial
DHTMLExtreme
 
Introduction to java script
DivyaKS12
 
Java Script An Introduction By HWA
Emma Wood
 
Java script Learn Easy
prince Loffar
 
Javascript
Rajavel Dhandabani
 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Introduction to JavaScript
Andres Baravalle
 
Javascript tutorial
Abhishek Kesharwani
 
Javascript
D V BHASKAR REDDY
 
Javascript by geetanjali
Geetanjali Bhosale
 
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Ad

Viewers also liked (20)

PPTX
An Overview of HTML, CSS & Java Script
Fahim Abdullah
 
KEY
Inside jQuery (2011)
Kenneth Auchenberg
 
PDF
C++ L02-Conversion+enum+Operators
Mohammad Shaker
 
PPT
JSON - Quick Overview
Signure Technologies
 
PPT
Java Script Object Notation (JSON)
Adnan Sohail
 
PDF
Fundamental JQuery
Achmad Solichin
 
PDF
Introduction to JSON
Kanda Runapongsa Saikaew
 
PDF
An Introduction to JavaScript: Week 3
Event Handler
 
PDF
An Introduction to JavaScript: Week 5
Event Handler
 
PPTX
The big bang theory - UNIT 2
lm092068
 
PPTX
Introduction to Java Script
Vijay Kumar Verma
 
PPT
Java Script
siddaram
 
PPTX
8. java script
AnusAhmad
 
PDF
Introduction to JavaScript: Week Two
Event Handler
 
PPT
JAVA SCRIPT
Go4Guru
 
PDF
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
PDF
Unchallengeable miracle of Holy Quran
yoursincerefriend
 
PDF
An Introduction to JavaScript: Week 4
Event Handler
 
PPTX
The big bang theory of social recruiting
FastCollab
 
PDF
jQuery for beginners
Siva Arunachalam
 
An Overview of HTML, CSS & Java Script
Fahim Abdullah
 
Inside jQuery (2011)
Kenneth Auchenberg
 
C++ L02-Conversion+enum+Operators
Mohammad Shaker
 
JSON - Quick Overview
Signure Technologies
 
Java Script Object Notation (JSON)
Adnan Sohail
 
Fundamental JQuery
Achmad Solichin
 
Introduction to JSON
Kanda Runapongsa Saikaew
 
An Introduction to JavaScript: Week 3
Event Handler
 
An Introduction to JavaScript: Week 5
Event Handler
 
The big bang theory - UNIT 2
lm092068
 
Introduction to Java Script
Vijay Kumar Verma
 
Java Script
siddaram
 
8. java script
AnusAhmad
 
Introduction to JavaScript: Week Two
Event Handler
 
JAVA SCRIPT
Go4Guru
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
Unchallengeable miracle of Holy Quran
yoursincerefriend
 
An Introduction to JavaScript: Week 4
Event Handler
 
The big bang theory of social recruiting
FastCollab
 
jQuery for beginners
Siva Arunachalam
 
Ad

Similar to Java script (20)

PPTX
CSC PPT 12.pptx
DrRavneetSingh
 
PPTX
JavaScripts & jQuery
Asanka Indrajith
 
PPTX
Java Script basics and DOM
Sukrit Gupta
 
PDF
Jscript Fundamentals
rspaike
 
PPTX
JavaScript_III.pptx
rashmiisrani1
 
PPTX
Final Java-script.pptx
AlkanthiSomesh
 
PDF
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
PPTX
JavaScript with Syntax & Implementation
Soumen Santra
 
PPTX
Java script
Sukrit Gupta
 
PDF
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
PDF
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
kavigamage62
 
PPT
Javascript1
anas Mohtaseb
 
PPTX
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
KelemAlebachew
 
PPTX
BITM3730Week6.pptx
MattMarino13
 
PPTX
JavaScript New Tutorial Class XI and XII.pptx
rish15r890
 
DOC
2javascript web programming with JAVA script
umardanjumamaiwada
 
DOCX
Basic Java script handouts for students
shafiq sangi
 
PDF
javascriptPresentation.pdf
wildcat9335
 
PPTX
Lecture 5 javascript
Mujtaba Haider
 
CSC PPT 12.pptx
DrRavneetSingh
 
JavaScripts & jQuery
Asanka Indrajith
 
Java Script basics and DOM
Sukrit Gupta
 
Jscript Fundamentals
rspaike
 
JavaScript_III.pptx
rashmiisrani1
 
Final Java-script.pptx
AlkanthiSomesh
 
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
JavaScript with Syntax & Implementation
Soumen Santra
 
Java script
Sukrit Gupta
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
kavigamage62
 
Javascript1
anas Mohtaseb
 
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
KelemAlebachew
 
BITM3730Week6.pptx
MattMarino13
 
JavaScript New Tutorial Class XI and XII.pptx
rish15r890
 
2javascript web programming with JAVA script
umardanjumamaiwada
 
Basic Java script handouts for students
shafiq sangi
 
javascriptPresentation.pdf
wildcat9335
 
Lecture 5 javascript
Mujtaba Haider
 

More from Soham Sengupta (20)

PPTX
Spring method-level-secuirty
Soham Sengupta
 
PPTX
Spring security mvc-1
Soham Sengupta
 
PDF
JavaScript event handling assignment
Soham Sengupta
 
PDF
Networking assignment 2
Soham Sengupta
 
PDF
Networking assignment 1
Soham Sengupta
 
PPT
Sohams cryptography basics
Soham Sengupta
 
PPT
Network programming1
Soham Sengupta
 
PPT
JSR-82 Bluetooth tutorial
Soham Sengupta
 
PPSX
Xmpp and java
Soham Sengupta
 
PPT
Core java day2
Soham Sengupta
 
PPT
Core java day1
Soham Sengupta
 
PPT
Core java day4
Soham Sengupta
 
PPT
Core java day5
Soham Sengupta
 
PPT
Exceptions
Soham Sengupta
 
PPSX
Java.lang.object
Soham Sengupta
 
PPTX
Soham web security
Soham Sengupta
 
PPTX
Html tables and_javascript
Soham Sengupta
 
PPT
Html javascript
Soham Sengupta
 
PPS
Sohamsg ajax
Soham Sengupta
 
Spring method-level-secuirty
Soham Sengupta
 
Spring security mvc-1
Soham Sengupta
 
JavaScript event handling assignment
Soham Sengupta
 
Networking assignment 2
Soham Sengupta
 
Networking assignment 1
Soham Sengupta
 
Sohams cryptography basics
Soham Sengupta
 
Network programming1
Soham Sengupta
 
JSR-82 Bluetooth tutorial
Soham Sengupta
 
Xmpp and java
Soham Sengupta
 
Core java day2
Soham Sengupta
 
Core java day1
Soham Sengupta
 
Core java day4
Soham Sengupta
 
Core java day5
Soham Sengupta
 
Exceptions
Soham Sengupta
 
Java.lang.object
Soham Sengupta
 
Soham web security
Soham Sengupta
 
Html tables and_javascript
Soham Sengupta
 
Html javascript
Soham Sengupta
 
Sohamsg ajax
Soham Sengupta
 

Recently uploaded (20)

PPTX
EU POPs Limits & Digital Product Passports Compliance Strategy 2025.pptx
Certivo Inc
 
PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PPTX
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
PDF
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 
EU POPs Limits & Digital Product Passports Compliance Strategy 2025.pptx
Certivo Inc
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
oapresentation.pptx
mehatdhavalrajubhai
 
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 

Java script

  • 1. JavaScript language fundamentals Learning Objectives Brief history of JavaScript Uses Language features Inclusion of script in HTML <noscript> and hiding scripts Scripts inside <body> and <head> External scripts
  • 2. Brief history of JavaScript Netscape developed a scripting language called LiveScript Supported both client side and server side scripting Netscape Navigator 2 (support for java applets and LiveScript renamed as JavaScript1.1) Microsoft- JScript IE 3 1997 ECMA (European Computer Manufacturers Association) Standardized ECMA script Opera supporting JavaScript 1.1 W3C standardized DOM to access HTML and XML JavaScript 1.2
  • 3. Response HTML file JAVA SCRIPT Request Servlet files JSP files HTML files Client Web Server Script executes locally and interacts with the browser Programs executes on the server and sends the response
  • 4. Uses • To create more interactive pages- client side validations etc. • To generate html dynamically. • Event handling • To enhance browser capabilities by giving it a better look – printing on status bar etc. • Interaction with embedded components like applets and active x controls. Language Features • Object based language:no object inheritance and subclassing. Object -based because it depends on built-in objects to function. • Semicolon, as separator for multiple statements in the same line. • Syntax similar to c++ and java • Case sensitive • Loosely typed • Platform independent • Interpreted
  • 5. Scripts in HTML <HTML><HEAD><TITLE>Hello</TITLE></HEAD> <BODY> First java script code<br> <SCRIPT> //Java script single line comment document.write(“Hello java script”) /* java script script multi-line comment */ </SCRIPT></BODY></HTML> NOSCRIPT and hiding scripts Some browser don’t support javascript. They will display the javascript on the web page since they cannot interpret. To avoid that the script need to be commented. Also for such browsers <NOSCRIPT> tag may be used which can display alternative text for scripts. <SCRIPT> <!— document.write(“Hello java script”) --> </SCRIPT> <NOSCRIPT>Java script is not supported</NOSCRIPT>
  • 6. External Script <HTML> <HEAD> <BODY> <SCRIPT LANGUAGE=“JavaScript” SRC=“JSfile.js”> </SCRIPT> </BODY> </HTML> JSfile.js document.write(“Hello”) Scripts inside body and head Inside head only declarations should be done. No write statements must appear inside head tag. <HTML><HEAD><TITLE>Hello</TITLE> <SCRIPT> document.write(“Hello java script”) </SCRIPT> </HEAD> <BODY></BODY> </HTML> Incorrect
  • 7. Nuts and Bolts Learning Objectives Variables and datatypes Conversion Operators Control statements Arrays Functions
  • 8. Variables and Datatypes • Variable names must begin with a letter, under-score or $., subsequent characters can be letter or number. • Variables need not be declared in JavaScript. They just need to be assigned with proper data. They are called data stores. • Data types supported by Java Script are a) Numeric – integer and floating point numbers (64 bit, IEE754 floating point) b) Strings c) Boolean- true, false d) Null, Undefined and NaN <HTML><HEAD><SCRIPT LANGUAGE=“JavaScript” > $I=“hello” </SCRIPT></HEAD> <BODY><SCRIPT LANGUAGE=“JavaScript”> document.write($I) </script> </body>
  • 9. Conversion: parseInt() and parseFloat() Operators Arithmetic: + - * / % += -= *= /= %= Logical: & | ! && || Relational: > >= < <= == != String concatenation: + Bit wise: >> << >>> >>= <<= >>>= Mixing up datatypes: S=“abc” I=123 document.write(S+I)  abc123 S=“abc” B=true document.write(S+B)  abctrue B=true I=123 document.write(B+1)  124
  • 10. Control statements • Same as in c++ or java • if else • for • while • do .. while • switch <HTML><HEAD><SCRIPT LANGUAGE=“JavaScript” > </SCRIPT></HEAD> <BODY><SCRIPT LANGUAGE=“JavaScript”> i=15 b=true for(j=2;j<=i/2;j++){ if(i%j==0){ b=false; break;} } if(b) document.write(i + “ is a prime number”) else document.write(i + “ is not a prime number”)</script> </body></html>
  • 11. Arrays • Declaration: are objects in JavaScript a= new Array(3) a[0]=1 a[1]=2 a[2]=3 • A single array can hold any kind of data junk= new Array(3) junk[0]=“Sunday” junk[1]=0 junk[2]=true • Array length a.length • Array size is incremented dynamically a= new Array() a[4]=4 a.length is 5 • Initialized array week=new Array(“sun”,”mon”,”tue”,”wed”,”thu”,”fri”,”sat”) document.write(week[0]) sun document.write(week) sun, mon, tue, wed … • Array of array: matrix= new Array(new Array(1,2,3), new Array(4,5,6) a[0][1] 2
  • 12. Function • Creation <html> <head> <script language=“JavaScript”> <!-- function display(x){ document.write(x)} --> </script> </head> <body> <script> <!— display(“hello”) --> </script> </body> </html> • Function with return values <html><head> <script language=“JavaScript”> <!-- function isNumber(x){ for(i=0;i<x.length;i++){ if(x.charAt(i)<‘0’ || x.charAt(i)>’9’) return false }r eturn true } --> </script></head><body> <script> <!— if(isNumber(“123”) document.write(“number”) else document.write(“not a number”) --></script></body></html>
  • 13. •Calling a function function display(x){ if(x==null) x=“Greetings” document.write(x) } Can be called as : display() or display(“hello”) No overloading possible. If overloaded functions are provided, only the last function is considered •Function arguments: arguments array can be used to collect the arguments of a function. <script language=“JavaScript”> <!-- function sum(){ total=0 for(j=0;j<sum.arguments.length;j++){ total+=sum.arguments[j]; document.write(sum)} --></script>
  • 14. •Local and Global variables Local variables are created using var <!-- function sum(){ total=0  var total=0 then it is available only in the function for(j=0;j<sum.arguments.length;j++){ total+=sum.arguments[j]; } --></script> …< script> <!— document.write(total) // ok doesn't display if local variable --> </script>
  • 15. JavaScript Object Model, window object Learning Objectives Object Model window object properties methods events Example communicating with the user Example displaying status bar messages on window events Example working with timer
  • 16. JavaScript Object Model • Also called DOM (document object model) or web browser object model. • JavaScript interacts with the web browser using the objects defined in the Object model. windowdocument  link history anchor location image frames formbutton, text, password,radio, checkbox, select submit, reset, hidden Array, String, Date, Math
  • 17. window object •window is the default object that is available to the JavaScript. •document.write  document is an object inside window and instead of document.write we can also write window.document.write implying write on current window’s document. •Properties: name, self, top, parent, opener, defaultStatus, status, closed, length Methods: alert(displayString), String prompt(question,defaultanswer), boolean confirm(question), Timer setTimeOut(expression, millsecs), clearTimeOut(timerobj), blur(), focus(), open(url,name,[options]), close() Events: onLoad, onUnload, onFocus, onBlur, OnError [options]: menubar=,toolbar,status, width=, height=
  • 18. Communicating with user <html><head> <script> function communicate(){ alert(“Hello”) s=prompt(“What is your name”, “xyz”) b=confirm(“Do you want to see your name displayed in colors”) a=new Array(“RED”,”GREEN”,”BLUE”,”YELLOW”, “BLACK”,”PURPLE) while(b){ document.write(“<font color=“+a[i]+”>”+s+”</font>”) if(i++>a.length)i=0 b=confirm(“Do you want to continue”)}} </script> </head><body onUnload=“alert(‘Bye!’)”> <script> communicate()</script> </body></html>
  • 19. status bar and window events <html><head> <script> function setStatus(x){ status=x } </script> </head> <body onLoad=“defaultStatus=‘welcome’” onBlur=“setStatus(‘OUT’) onFocus=“setStatus(“ON”)> Look at the status bar </body> </html>
  • 20. Timer <html><head> <script> a=new Array(“Welcome”,”to”,”jis”) i=0 function setTimer(){ setTimeout(“display()”,1000); } function display(){ status=a[i] i=i++%3 setTimer() }
  • 21. open() <html> <head> <title>win4</title> </head> <body onLoad="open('win2.html','x' ,'menubar=0')"> 1. HTTP is a ______________ protocol<br> a) application layer<br> b) session layer<br> c) transport layer<br> d) network layer </body> </html>
  • 22. location, frames, history, Opening a new page on top window
  • 23. location <html><head> </head> <body> <form> <input type=button onCLick=“location.href=‘x.html’”> </form> </body> </html> Properties: href, port,path, pathname
  • 24. <html><head> <title>Shop with us</title> <script> function display(x){ switch(x){ case 'left': parent.b.l.location.href="img.jpg" break case 'right': parent.b.frames[1].location.href="img.jpg" break case 'top': top.location.href="img.jpg" break case 'bottom' : parent.b.location.href="img.jpg" break case 'self' : location.href="img.jpg" break default: location.href=history.back() }} </script></head>
  • 25. <body> <form> <input type="button" value="Left" onClick="display('left')"> <input type="button" value="Right" onClick="display('right')"> <input type="button" value="Top" onClick="display('top')"> <input type="button" value="Bottom" onClick="display('bottom')"> <input type="button" value="self" onClick="display('self')"> <input type="button" value="back" onClick="display('xx')"> </form> </body> </html>
  • 26. document Properties: images[], forms[], links[], anchors[],bgColor, fgColor, title, linkColor, alinkColor, vlinkColor Methods: open([mimetype]), write(expr1), close() Example 1:bgColor and fgColor <body onFocus=“bgColor=‘white’;fgColor=‘black’” onBlur=“bgColor=‘black’;fgColor=‘black’”> Example 2:Generating a document <html><head><script> function generate(){ win=open("","gen") win.document.open("texthtml") win.document.write("<html><body onLoad=alert('ok')><U>Welcome</U>") win.document.write("</body></html>") win.document.close() } </script> <body><form><input type=‘button’ onClick=‘generate()’></form></body> </html>
  • 27. images Properties:border, height, width, src, name, complete Creating new Image object: im=new Image() im=new Image(40,50) Events: onLoad, onError, onAbort, onMouseOver, onMouseOut, onDblClick Example 1: <html><head> <script> i=0 imgs=new Array("image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg") function change(){ document.images[0].src=imgs[i++ % imgs.length]} </script></head> <body><img src="image5.jpg" onMouseOver="change()"> </body> </html>
  • 28. On the internet it takes time to download the image. So to check if the image has been downloaded and do the required we need image as object. <script> i=0 imgs=new Array(5) for(i=0;i<5;i++){ imgs[i]=new Image() imgs[i].src="image"+ (i+1)+".jpg“ } i=0 function set(){ setTimeout('change()',1000) } function change(){ if(imgs[i].complete){ document.images[0].src=imgs[i++ % imgs.length].src set()}} </script> </head> <body><img src="image5.jpg"> <script>set()</script></body></html>
  • 29. form Properties: action, method, name, elements[], target Events: onSubmit, onReset Form elements: Events:All form elements: onBlur, onFocus Select,text, textarea: onChange Text, texrarea: onSelect Button,submit,reset,radio,checkbox: onClick Button: onMouseDown, onMouseUp, TextArea: onKeyDown, onKeyUp, onKeyPress Properties: All : name, type, value (except select) radio, checkbox: checked, defaultChecked select: length, options[], selectedIndex text, password, textarea:defaultValue Methods: All form elements: focus(), blur() button,submit, reset: click()
  • 30. Example 1: Working with text, radio and checkbox <html><head><title>Validate</title><script> <!-- function check(){ with(document.forms[0]){ if ((name.value=="") ){ alert("Please ensure that all fields are filled up") return false } if(like[0].checked) s= "Thankyou, "+name.value +"." else s="Sorry !" s=s+" As per your suggestion we shall look into areas:("; for(i=0;i<better.length;i++) if (better[i].checked) s=s+ better[i].value+"," s=s+" and more ) for further improvements " } alert(s) return true}
  • 31. //--> </script> </head><body> <form action="Frame.html" onSubmit="return check()"> Name: <input type=text name=name><br><br> Do you like our site <input type=radio name="like" checked>Yes <input type=radio name="like" >No<br><br> Tell us how we can make this site better for you:<br> <input type=checkbox name="better" value="Change bgcolor">Change the bg color<br> <input type=checkbox name="better" value="Change fgcolor">Change the fg color<br> <input type=checkbox name="better" value="Change layout">Change the layout<br> <input type=checkbox name="better" value="More services">Include more services<br><br> <input type=submit></form> </body> </html>
  • 32. Example 2: Working with select <html><head><script> <!-- function check(){ i=document.f1.choose.options.selectedIndex; if(i!=0){ if(i==1) alert("Correct"); else alert("Your choice, "+ document.f1.choose.options[i].text +"- is incorrect"); }} //--> </script></head> <body> <form name=f1> Which of the following is not true about JavaScript? <select name="choose" onChange="check()">
  • 33. <option>-------Select the best answer--------</option> <option>JavaScript is object-oriented language</option> <option>JavaScript is loosely typed language</option> <option>JavaScript is used for client side validations</option> <option>JavaScript is platform independent</option> </select> </form> </body> </html>
  • 34. link, anchor and history links, anchors: array properties: href, hostname, pathname, port, target, protocol Events: onClick, onDblClick, onKeyDown, onKeyUp, onKeyPress, onMouseDown, onMouseUp, onMouseOver, onMouseOut Example: Game <html><head> <script> arr=new Array(‘one.hif’,’two.gif’) i=0 im=“” function f(x){ r=Math.floor(Math.random()*2) document.images[x].src=arr[r] if(i==0) im=arr[r] if(i++>0 && im==arr[r]) alert(“You have won in “+ i + “ attempts”) } </script>
  • 35. <body> <table><tr> <td><a href=“#” onClick=f(1)><img src=“blank.gif”></a></td> <td><a href=“#” onClick=f(2)><img src=“blank.gif”></a></td></tr> <td><a href=“#” onClick=f(3)><img src=“blank.gif”></a></td> <td><a href=“#” onClick=f(4)><img src=“blank.gif”></a></td></tr> </table> </body> </html> History Property: length Methods: back() forward() go(x)
  • 36. Math Properties: PI, E Methods: sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), round(x), floor(x), ceil(x), max(x,y), min(x,y), sqrt(x), pow(x,y), random(), log(x) Rounding: with(Math){ X=floor(3.5)  3 Y=ceil(3.5)4 Z=round(3.5) 4 } r=Math.floor(Math.random()*2) r between 0 and 1.
  • 37. Date object var dt= new Date(); Creates a new date object which contains system’s current date and time. Methods: getDate() getMonth() getYear() getHours() getMinutes() getSeconds() setDate(value) setMonth(value) setYear(value) setHours(value) setMinutes(value) setSeconds(value) toGMTString() toLocalString() Example 1: <html><head><title>time</title><script> <!-- function setTime() { dt= new Date(); str=dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds(); document.forms[0].time.value=str; timer=setTimeout("setTime()",1000); } </script>
  • 38. </head> <body><form> <input type=text name="time" readonly size=6> </form> <script>setTime()</script> </body></html> Example 2: Difference between two dates: <script> Function diff(){ dt1=new Date(); dt2=new Date(2005,8,5) millsec=1000*60*60*24 Days=Math.round((dt1-dt2)/millsec) alert(“no of days “+ days) }
  • 39. String object Method Example HTML anchor(aname) “Part2”.anchor(“p2”) <a name=“p2”>Part2</a> big() “Welcome”.big() <BIG>Welcome</BIG> blink() “Highlights”.blink() <BLINK>Highlights</BLINK> bold() “Hello”.bold() <B>Hello</B> italics() “sky”.italics() <I>Sky</I> link(url) Yahoo.link( www.yahoo.com) <a href=www.yahoo.com> Yahoo</a> small() “Rights reserved”.small() <small>Rights reserver</small> strike() “strike”.strike() <strike>strike</strike> sub() “h”+”2”.sub()+ “o” h <SUB>2</SUB>o sup() “E=MC”+”2”.sup() E=MC<SUP>2</SUP>
  • 40. Methods Examples Results toLowerCase() “Hi”.toLowerCase() hi toUpperCase() “hi”.toUpperCase() HI length “hi”.length 2 indexOf(searchText, “hello.indexOf(“e”,0) 1 startposition) substring(startpos, endpos) “hello”.substring(1,3) el charAt(indexPos) “hello”.charAt(4) O