SlideShare a Scribd company logo
Core JavaScript
(Properties and Methods)
JavaScript Arrays
• JavaScript arrays are used to store multiple values in a single variable.
• An array is a special variable, which can hold more than one value at a time.
• Example
▫ If you have a list of items (a list of car names, for example), storing the cars in single variables
could look like this:
var car1 = "Saab";
var car2 = "Volvo";
var car3 = "BMW";
• However, what if you want to loop through the cars and find a specific one? And
what if you had not 3 cars, but 300?
• The solution is an array!
• An array can hold many values under a single name, and you can access the values by referring to
an index number.
var cars = [“Maruti", "Volvo", "BMW"];
JavaScript Arrays: Example
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
Access the Elements of an Array
• You refer to an array element by referring to the
index number.
• This statement accesses the value of the first
element in cars:
var name = cars[0];
• This statement modifies the first element in
cars:
Cars[0] = "Opel";
Access the Elements of an Array
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars[0];
</script>
</body>
</html>
Arrays are Objects
• Arrays are a special type of objects.
• Arrays use numbers to access its "elements".
• In this example, person[0] returns John:
var person = ["John", "Doe", 46];
• Objects use names to access its "members".
• In this example, person.firstName returns
John
var person = {firstName:"John", lastName:"Doe", age:46};
Array Properties and Methods
• The length property of an array returns the
length of an array (the number of array
elements).
• Examples
var x = cars.length; // The length property returns
the number of elements
var y = cars.sort(); // The sort() method sorts
arrays
Length of An Array
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>The length property returns the length of an array.</p>
<p id="demo"></p>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.length;
</script>
</body>
</html>
Looping Array Elements
• The best way to loop through an array, is using a
"for" loop:
• Example
var fruits, text, fLen, i;
fruits = ["Banana", "Orange", "Apple", "Mango"];
fLen = fruits.length;
text = "<ul>";
for (i = 0; i < fLen; i++) {
text += "<li>" + fruits[i] + "</li>";
}
Looping Array Elements
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>The best way to loop through an array is using a standard for loop:</p>
<p id="demo"></p>
<script>
var fruits, text, fLen, i;
fruits = ["Banana", "Orange", "Apple", "Mango"];
fLen = fruits.length;
text = "<ul>";
for (i = 0; i < fLen; i++) {
text += fruits[i] + "<br>";
}
text += "</ul>";
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
JavaScript Booleans
• A JavaScript Boolean represents one of two
values: true or false.
• Boolean Values
▫ Very often, in programming, you will need a data
type that can only have one of two values, like
 YES / NO
 ON / OFF
 TRUE / FALSE
• For this, JavaScript has a Boolean data type. It
can only take the values true or false.
JavaScript Booleans
• The Boolean() Function
▫ You can use the Boolean() function to find out if
an expression (or a variable) is true:
• Example
Boolean(10 > 9)
JavaScript Booleans: CODE Example
<!DOCTYPE html>
<html>
<body>
<p>Display the value of Boolean(10 > 9):</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = Boolean(10 > 9);
}
</script>
</body>
</html>
JavaScript Date Formats
• A JavaScript date can be written as a string:
Sun Feb 05 2017 20:32:29 GMT+0530 (India Standard Time)
• or as a number:
1486306949768
• Dates written as numbers, specifies the number of milliseconds
since January 1, 1970, 00:00:00.
• Displaying Dates
▫ Example
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Date();
</script>
JavaScript Date Methods
• Date methods let
you get and set date
values (years,
months, days, hours,
minutes, seconds,
milliseconds)
• Date Get Methods
• Get methods are
used for getting a
part of a date. Here
are the most
common
(alphabetically):
Method Description
getDate()
Get the day as a number (1-
31)
getDay()
Get the weekday as a
number (0-6)
getFullYear()
Get the four digit year
(yyyy)
getHours() Get the hour (0-23)
getMilliseconds()
Get the milliseconds (0-
999)
getMinutes() Get the minutes (0-59)
getMonth() Get the month (0-11)
getSeconds() Get the seconds (0-59)
getTime()
Get the time (milliseconds
since January 1, 1970)
JavaScript Date Methods
<!DOCTYPE html>
<html>
<body>
<p>The getFullYear() method returns the full year of a date:</p>
<p id="demo"></p>
<script>
var d = new Date();
document.getElementById("demo").innerHTML = d.getFullYear();
</script>
</body>
</html>
JavaScript Date Methods
<!DOCTYPE html>
<html>
<body>
<p>The internal clock in JavaScript starts at midnight January 1, 1970.</p>
<p>The getTime() function returns the number of milliseconds since then:</p>
<p id="demo"></p>
<script>
var d = new Date();
document.getElementById("demo").innerHTML = d.getTime();
</script>
</body>
</html>
JavaScript Date Methods
• Date methods let
you get and set date
values (years,
months, days, hours,
minutes, seconds,
milliseconds)
• Date Set Methods
• Set methods are
used for setting a
part of a date. Here
are the most
common
(alphabetically):
Date Set Methods
Method Description
setDate()
Set the day as a number
(1-31)
setFullYear()
Set the year (optionally
month and day)
setHours() Set the hour (0-23)
setMilliseconds()
Set the milliseconds (0-
999)
setMinutes() Set the minutes (0-59)
setMonth() Set the month (0-11)
setSeconds() Set the seconds (0-59)
setTime()
Set the time
(milliseconds since
January 1, 1970)
The setDate() Method
setDate() sets the day of the month (1-31):
<!DOCTYPE html>
<html>
<body>
<p>The setDate() method sets the date of a month.</p>
<p id="demo"></p>
<script>
var d = new Date();
d.setDate(15);
document.getElementById("demo").innerHTML = d;
</script>
</body>
</html>
The setDate() Method
The setDate() method can also be used to add days to a date:
<!DOCTYPE html>
<html>
<body>
<p>The setDate() method can be used to add days to a date.</p>
<p id="demo"></p>
<script>
var d = new Date();
d.setDate(d.getDate() + 50);
document.getElementById("demo").innerHTML = d;
</script>
</body>
</html>
JavaScript Math Object
• The JavaScript Math object allows you to
perform mathematical tasks on numbers.
• Example
Math.PI;
• Math.round()
▫ Math.round(x) returns the value of x rounded to
its nearest integer:
• Example
Math.round(4.7); // returns 5
Math.round(4.4); // returns 4
Math Properties (Constants)
• JavaScript provides 8 mathematical constants
that can be accessed with the Math object:
• Example
 Math.E // returns Euler's number
 Math.PI // returns PI
 Math.SQRT2 // returns the square root of 2
 Math.SQRT1_2 // returns the square root of ½
 Math.LN2 // returns the natural logarithm of 2
 Math.LN10 // returns the natural logarithm of 10
 Math.LOG2E // returns base 2 logarithm of E
 Math.LOG10E // returns base 10 logarithm of E
JavaScript Math Object Method:
Round()
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Math.round()</h1>
<p>Math.round(x) returns the value of x rounded down to its nearest integer:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.round(4.4);
</script>
</body>
</html>
JavaScript Math Object: pow()
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Math.pow()</h1>
<p>Math.pow(x,y) returns the value of x to the power of y:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.pow(8,2);
</script>
</body>
</html>
JavaScript Math Object: sqrt()
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Math.sqrt()</h1>
<p>Math.sqrt(x) returns the square root of x:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.sqrt(64);
</script>
</body>
</html>
JavaScript Math Object: abs()
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Math.abs()</h1>
<p>Math.abs(x) returns the absolute (positive) value of x:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.abs(-4.4);
</script>
</body>
</html>
JavaScript Math Object: abs()
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Math.abs()</h1>
<p>Math.abs(x) returns the absolute (positive) value of x:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.abs(-4.4);
</script>
</body>
</html>
Math Object Methods
Method Description
abs(x) Returns the absolute value of x
acos(x) Returns the arccosine of x, in radians
asin(x) Returns the arcsine of x, in radians
atan(x) Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
atan2(y, x) Returns the arctangent of the quotient of its arguments
ceil(x) Returns the value of x rounded up to its nearest integer
cos(x) Returns the cosine of x (x is in radians)
exp(x) Returns the value of E
x
floor(x) Returns the value of x rounded down to its nearest integer
log(x) Returns the natural logarithm (base E) of x
max(x, y, z, ..., n) Returns the number with the highest value
min(x, y, z, ..., n) Returns the number with the lowest value
pow(x, y) Returns the value of x to the power of y
random() Returns a random number between 0 and 1
round(x) Returns the value of x rounded to its nearest integer
sin(x) Returns the sine of x (x is in radians)
sqrt(x) Returns the square root of x
tan(x) Returns the tangent of an angle
Number Methods and Properties
Property Description
MAX_VALUE Returns the largest number possible in JavaScript
MIN_VALUE Returns the smallest number possible in JavaScript
NEGATIVE_INFI
NITY
Represents negative infinity (returned on overflow)
NaN Represents a "Not-a-Number" value
POSITIVE_INFIN
ITY
Represents infinity (returned on overflow)
Number Properties
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
Number.MAX_VALUE;
</script>
</body>
</html>
Number Methods
• The toString() Method
▫ toString() returns a number as a string.
• The toExponential() Method
▫ toExponential() returns a string, with a number rounded
and written using exponential notation.
• The toFixed() Method
▫ toFixed() returns a string, with the number written with a
specified number of decimals:
• The toPrecision() Method
▫ toPrecision() returns a string, with a number written
with a specified length:
• The valueOf() Method
▫ valueOf() returns a number as a number.
The toFixed() Method
<!DOCTYPE html>
<html>
<body>
<p>The toFixed() method rounds a number to a given number of digits.</p>
<p>For working with money, toFixed(2) is perfect.</p>
<p id="demo"></p>
<script>
var x = 9.656;
document.getElementById("demo").innerHTML =
x.toFixed(0) + "<br>" +
x.toFixed(2) + "<br>" +
x.toFixed(4) + "<br>" +
x.toFixed(6);
</script>
</body>
</html>
Converting Variables to Numbers
• There are 3 JavaScript methods that can be used to
convert variables to numbers:
▫ The Number() method
▫ The parseInt() method
▫ The parseFloat() method
• These methods are not number methods,
but global JavaScript methods.
Method Description
Number() Returns a number, converted from its argument.
parseFloat() Parses its argument and returns a floating point number
parseInt() Parses its argument and returns an integer
The parseInt() Method
parseInt() parses a string and returns a whole number. Spaces are allowed. Only the first number is
returned:
<!DOCTYPE html>
<html>
<body>
<p>The global JavaScript function parseInt() converts strings to numbers:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
parseInt("10") + "<br>" +
parseInt("10.33") + "<br>" +
parseInt("10 6") + "<br>" +
parseInt("10 years") + "<br>" +
parseInt("years 10");
</script>
</body>
</html>
JavaScript Regular Expressions
• A regular expression is a sequence of characters that
forms a search pattern.
• When you search for data in a text, you can use this
search pattern to describe what you are searching
for.
• A regular expression can be a single character, or a
more complicated pattern.
• Regular expressions can be used to perform all types
of text search and text replace operations.
• Syntax
/pattern/modifiers;
Using String Methods
With a Regular Expression
• In JavaScript, regular expressions are often used
with the two string methods: search() and
replace().
• The search() method uses an expression to
search for a match, and returns the position of
the match.
• The replace() method returns a modified
string where the pattern is replaced.
Use String replace() With a Regular
Expression
<!DOCTYPE html>
<html>
<body>
<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>
<button onclick="myFunction()">Try it</button>
<p id="demo">Please visit Microsoft!</p>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace("Microsoft","W3Schools");
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>

More Related Content

What's hot (20)

Java Script
Java ScriptJava Script
Java Script
Kalidass Balasubramaniam
 
Java script
Java scriptJava script
Java script
Soham Sengupta
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
Dominic Arrojado
 
Java script
Java scriptJava script
Java script
vishal choudhary
 
Java script
Java scriptJava script
Java script
Shyam Khant
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
Mohammad Imam Hossain
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
borkweb
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7
phuphax
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
Think jQuery
Think jQueryThink jQuery
Think jQuery
Ying Zhang
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
Broadleaf Commerce
 
Introduction to Grails Framework
Introduction to Grails FrameworkIntroduction to Grails Framework
Introduction to Grails Framework
PT.JUG
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
Aaron Gustafson
 
Html5 appunti.0
Html5   appunti.0Html5   appunti.0
Html5 appunti.0
orestJump
 
Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS Framework
Mohd Imran
 
jQuery Beginner
jQuery BeginnerjQuery Beginner
jQuery Beginner
kumar gaurav
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
Brian Moschel
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
H K
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
borkweb
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7
phuphax
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
Introduction to Grails Framework
Introduction to Grails FrameworkIntroduction to Grails Framework
Introduction to Grails Framework
PT.JUG
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
Aaron Gustafson
 
Html5 appunti.0
Html5   appunti.0Html5   appunti.0
Html5 appunti.0
orestJump
 
Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS Framework
Mohd Imran
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
H K
 

Similar to FYBSC IT Web Programming Unit III Core Javascript (20)

Java script
Java scriptJava script
Java script
Shagufta shaheen
 
1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications
surajshreyans
 
Learn java script
Learn java scriptLearn java script
Learn java script
Mahmoud Asadi
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
Jalpesh Vasa
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
William Myers
 
JavaScript own objects(Web Technology)
JavaScript own objects(Web Technology)JavaScript own objects(Web Technology)
JavaScript own objects(Web Technology)
Dhananjaysinh Jhala
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
Cindy Royal
 
CSC PPT 13.pptx
CSC PPT 13.pptxCSC PPT 13.pptx
CSC PPT 13.pptx
DrRavneetSingh
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
KennyPratheepKumar
 
Variables 2
Variables 2Variables 2
Variables 2
Jesus Obenita Jr.
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
Web Zhao
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
BoneyGawande
 
03. Week 03.pptx
03. Week 03.pptx03. Week 03.pptx
03. Week 03.pptx
Vinc2ntCabrera
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
Asanka Indrajith
 
JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)
Beat Signer
 
Javascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para IniciantesJavascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para Iniciantes
GabrielSchiavo1
 
JavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentationJavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentation
M Sajid R
 
1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications
surajshreyans
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
Jalpesh Vasa
 
JavaScript own objects(Web Technology)
JavaScript own objects(Web Technology)JavaScript own objects(Web Technology)
JavaScript own objects(Web Technology)
Dhananjaysinh Jhala
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
Cindy Royal
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
Web Zhao
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
BoneyGawande
 
JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)
Beat Signer
 
Javascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para IniciantesJavascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para Iniciantes
GabrielSchiavo1
 
JavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentationJavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentation
M Sajid R
 
Ad

More from Arti Parab Academics (20)

COMPUTER APPLICATIONS Module 4.pptx
COMPUTER APPLICATIONS Module 4.pptxCOMPUTER APPLICATIONS Module 4.pptx
COMPUTER APPLICATIONS Module 4.pptx
Arti Parab Academics
 
COMPUTER APPLICATIONS Module 1 HPSY - Copy.pptx
COMPUTER APPLICATIONS Module 1 HPSY - Copy.pptxCOMPUTER APPLICATIONS Module 1 HPSY - Copy.pptx
COMPUTER APPLICATIONS Module 1 HPSY - Copy.pptx
Arti Parab Academics
 
COMPUTER APPLICATIONS Module 5.pptx
COMPUTER APPLICATIONS Module 5.pptxCOMPUTER APPLICATIONS Module 5.pptx
COMPUTER APPLICATIONS Module 5.pptx
Arti Parab Academics
 
COMPUTER APPLICATIONS Module 1 CAH.pptx
COMPUTER APPLICATIONS Module 1 CAH.pptxCOMPUTER APPLICATIONS Module 1 CAH.pptx
COMPUTER APPLICATIONS Module 1 CAH.pptx
Arti Parab Academics
 
COMPUTER APPLICATIONS Module 3.pptx
COMPUTER APPLICATIONS Module 3.pptxCOMPUTER APPLICATIONS Module 3.pptx
COMPUTER APPLICATIONS Module 3.pptx
Arti Parab Academics
 
COMPUTER APPLICATIONS Module 2.pptx
COMPUTER APPLICATIONS Module 2.pptxCOMPUTER APPLICATIONS Module 2.pptx
COMPUTER APPLICATIONS Module 2.pptx
Arti Parab Academics
 
Health Informatics- Module 5-Chapter 2.pptx
Health Informatics- Module 5-Chapter 2.pptxHealth Informatics- Module 5-Chapter 2.pptx
Health Informatics- Module 5-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 5-Chapter 3.pptx
Health Informatics- Module 5-Chapter 3.pptxHealth Informatics- Module 5-Chapter 3.pptx
Health Informatics- Module 5-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 4-Chapter 3.pptx
Health Informatics- Module 4-Chapter 3.pptxHealth Informatics- Module 4-Chapter 3.pptx
Health Informatics- Module 4-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 3-Chapter 2.pptx
Health Informatics- Module 3-Chapter 2.pptxHealth Informatics- Module 3-Chapter 2.pptx
Health Informatics- Module 3-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 4-Chapter 1.pptx
Health Informatics- Module 4-Chapter 1.pptxHealth Informatics- Module 4-Chapter 1.pptx
Health Informatics- Module 4-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 4-Chapter 2.pptx
Health Informatics- Module 4-Chapter 2.pptxHealth Informatics- Module 4-Chapter 2.pptx
Health Informatics- Module 4-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 3-Chapter 3.pptx
Health Informatics- Module 3-Chapter 3.pptxHealth Informatics- Module 3-Chapter 3.pptx
Health Informatics- Module 3-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 5-Chapter 1.pptx
Health Informatics- Module 5-Chapter 1.pptxHealth Informatics- Module 5-Chapter 1.pptx
Health Informatics- Module 5-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 3-Chapter 1.pptx
Health Informatics- Module 3-Chapter 1.pptxHealth Informatics- Module 3-Chapter 1.pptx
Health Informatics- Module 3-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 2-Chapter 2.pptx
Health Informatics- Module 2-Chapter 2.pptxHealth Informatics- Module 2-Chapter 2.pptx
Health Informatics- Module 2-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 1-Chapter 1.pptx
Health Informatics- Module 1-Chapter 1.pptxHealth Informatics- Module 1-Chapter 1.pptx
Health Informatics- Module 1-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 2-Chapter 3.pptx
Health Informatics- Module 2-Chapter 3.pptxHealth Informatics- Module 2-Chapter 3.pptx
Health Informatics- Module 2-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 2-Chapter 1.pptx
Health Informatics- Module 2-Chapter 1.pptxHealth Informatics- Module 2-Chapter 1.pptx
Health Informatics- Module 2-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 1-Chapter 2.pptx
Health Informatics- Module 1-Chapter 2.pptxHealth Informatics- Module 1-Chapter 2.pptx
Health Informatics- Module 1-Chapter 2.pptx
Arti Parab Academics
 
COMPUTER APPLICATIONS Module 1 HPSY - Copy.pptx
COMPUTER APPLICATIONS Module 1 HPSY - Copy.pptxCOMPUTER APPLICATIONS Module 1 HPSY - Copy.pptx
COMPUTER APPLICATIONS Module 1 HPSY - Copy.pptx
Arti Parab Academics
 
COMPUTER APPLICATIONS Module 1 CAH.pptx
COMPUTER APPLICATIONS Module 1 CAH.pptxCOMPUTER APPLICATIONS Module 1 CAH.pptx
COMPUTER APPLICATIONS Module 1 CAH.pptx
Arti Parab Academics
 
Health Informatics- Module 5-Chapter 2.pptx
Health Informatics- Module 5-Chapter 2.pptxHealth Informatics- Module 5-Chapter 2.pptx
Health Informatics- Module 5-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 5-Chapter 3.pptx
Health Informatics- Module 5-Chapter 3.pptxHealth Informatics- Module 5-Chapter 3.pptx
Health Informatics- Module 5-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 4-Chapter 3.pptx
Health Informatics- Module 4-Chapter 3.pptxHealth Informatics- Module 4-Chapter 3.pptx
Health Informatics- Module 4-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 3-Chapter 2.pptx
Health Informatics- Module 3-Chapter 2.pptxHealth Informatics- Module 3-Chapter 2.pptx
Health Informatics- Module 3-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 4-Chapter 1.pptx
Health Informatics- Module 4-Chapter 1.pptxHealth Informatics- Module 4-Chapter 1.pptx
Health Informatics- Module 4-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 4-Chapter 2.pptx
Health Informatics- Module 4-Chapter 2.pptxHealth Informatics- Module 4-Chapter 2.pptx
Health Informatics- Module 4-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 3-Chapter 3.pptx
Health Informatics- Module 3-Chapter 3.pptxHealth Informatics- Module 3-Chapter 3.pptx
Health Informatics- Module 3-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 5-Chapter 1.pptx
Health Informatics- Module 5-Chapter 1.pptxHealth Informatics- Module 5-Chapter 1.pptx
Health Informatics- Module 5-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 3-Chapter 1.pptx
Health Informatics- Module 3-Chapter 1.pptxHealth Informatics- Module 3-Chapter 1.pptx
Health Informatics- Module 3-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 2-Chapter 2.pptx
Health Informatics- Module 2-Chapter 2.pptxHealth Informatics- Module 2-Chapter 2.pptx
Health Informatics- Module 2-Chapter 2.pptx
Arti Parab Academics
 
Health Informatics- Module 1-Chapter 1.pptx
Health Informatics- Module 1-Chapter 1.pptxHealth Informatics- Module 1-Chapter 1.pptx
Health Informatics- Module 1-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 2-Chapter 3.pptx
Health Informatics- Module 2-Chapter 3.pptxHealth Informatics- Module 2-Chapter 3.pptx
Health Informatics- Module 2-Chapter 3.pptx
Arti Parab Academics
 
Health Informatics- Module 2-Chapter 1.pptx
Health Informatics- Module 2-Chapter 1.pptxHealth Informatics- Module 2-Chapter 1.pptx
Health Informatics- Module 2-Chapter 1.pptx
Arti Parab Academics
 
Health Informatics- Module 1-Chapter 2.pptx
Health Informatics- Module 1-Chapter 2.pptxHealth Informatics- Module 1-Chapter 2.pptx
Health Informatics- Module 1-Chapter 2.pptx
Arti Parab Academics
 
Ad

Recently uploaded (20)

Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptxChalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Himalayan Group of Professional Institutions (HGPI)
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdfGEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptxPEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptxSPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive LearningSustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 EmployeesOverview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdfIntroduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdfGEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptxPEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptxSPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive LearningSustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 EmployeesOverview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdfIntroduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 

FYBSC IT Web Programming Unit III Core Javascript

  • 2. JavaScript Arrays • JavaScript arrays are used to store multiple values in a single variable. • An array is a special variable, which can hold more than one value at a time. • Example ▫ If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: var car1 = "Saab"; var car2 = "Volvo"; var car3 = "BMW"; • However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300? • The solution is an array! • An array can hold many values under a single name, and you can access the values by referring to an index number. var cars = [“Maruti", "Volvo", "BMW"];
  • 3. JavaScript Arrays: Example <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var cars = ["Saab", "Volvo", "BMW"]; document.getElementById("demo").innerHTML = cars; </script> </body> </html>
  • 4. Access the Elements of an Array • You refer to an array element by referring to the index number. • This statement accesses the value of the first element in cars: var name = cars[0]; • This statement modifies the first element in cars: Cars[0] = "Opel";
  • 5. Access the Elements of an Array <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var cars = ["Saab", "Volvo", "BMW"]; document.getElementById("demo").innerHTML = cars[0]; </script> </body> </html>
  • 6. Arrays are Objects • Arrays are a special type of objects. • Arrays use numbers to access its "elements". • In this example, person[0] returns John: var person = ["John", "Doe", 46]; • Objects use names to access its "members". • In this example, person.firstName returns John var person = {firstName:"John", lastName:"Doe", age:46};
  • 7. Array Properties and Methods • The length property of an array returns the length of an array (the number of array elements). • Examples var x = cars.length; // The length property returns the number of elements var y = cars.sort(); // The sort() method sorts arrays
  • 8. Length of An Array <!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <p>The length property returns the length of an array.</p> <p id="demo"></p> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo").innerHTML = fruits.length; </script> </body> </html>
  • 9. Looping Array Elements • The best way to loop through an array, is using a "for" loop: • Example var fruits, text, fLen, i; fruits = ["Banana", "Orange", "Apple", "Mango"]; fLen = fruits.length; text = "<ul>"; for (i = 0; i < fLen; i++) { text += "<li>" + fruits[i] + "</li>"; }
  • 10. Looping Array Elements <!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <p>The best way to loop through an array is using a standard for loop:</p> <p id="demo"></p> <script> var fruits, text, fLen, i; fruits = ["Banana", "Orange", "Apple", "Mango"]; fLen = fruits.length; text = "<ul>"; for (i = 0; i < fLen; i++) { text += fruits[i] + "<br>"; } text += "</ul>"; document.getElementById("demo").innerHTML = text; </script> </body> </html>
  • 11. JavaScript Booleans • A JavaScript Boolean represents one of two values: true or false. • Boolean Values ▫ Very often, in programming, you will need a data type that can only have one of two values, like  YES / NO  ON / OFF  TRUE / FALSE • For this, JavaScript has a Boolean data type. It can only take the values true or false.
  • 12. JavaScript Booleans • The Boolean() Function ▫ You can use the Boolean() function to find out if an expression (or a variable) is true: • Example Boolean(10 > 9)
  • 13. JavaScript Booleans: CODE Example <!DOCTYPE html> <html> <body> <p>Display the value of Boolean(10 > 9):</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Boolean(10 > 9); } </script> </body> </html>
  • 14. JavaScript Date Formats • A JavaScript date can be written as a string: Sun Feb 05 2017 20:32:29 GMT+0530 (India Standard Time) • or as a number: 1486306949768 • Dates written as numbers, specifies the number of milliseconds since January 1, 1970, 00:00:00. • Displaying Dates ▫ Example <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Date(); </script>
  • 15. JavaScript Date Methods • Date methods let you get and set date values (years, months, days, hours, minutes, seconds, milliseconds) • Date Get Methods • Get methods are used for getting a part of a date. Here are the most common (alphabetically): Method Description getDate() Get the day as a number (1- 31) getDay() Get the weekday as a number (0-6) getFullYear() Get the four digit year (yyyy) getHours() Get the hour (0-23) getMilliseconds() Get the milliseconds (0- 999) getMinutes() Get the minutes (0-59) getMonth() Get the month (0-11) getSeconds() Get the seconds (0-59) getTime() Get the time (milliseconds since January 1, 1970)
  • 16. JavaScript Date Methods <!DOCTYPE html> <html> <body> <p>The getFullYear() method returns the full year of a date:</p> <p id="demo"></p> <script> var d = new Date(); document.getElementById("demo").innerHTML = d.getFullYear(); </script> </body> </html>
  • 17. JavaScript Date Methods <!DOCTYPE html> <html> <body> <p>The internal clock in JavaScript starts at midnight January 1, 1970.</p> <p>The getTime() function returns the number of milliseconds since then:</p> <p id="demo"></p> <script> var d = new Date(); document.getElementById("demo").innerHTML = d.getTime(); </script> </body> </html>
  • 18. JavaScript Date Methods • Date methods let you get and set date values (years, months, days, hours, minutes, seconds, milliseconds) • Date Set Methods • Set methods are used for setting a part of a date. Here are the most common (alphabetically): Date Set Methods Method Description setDate() Set the day as a number (1-31) setFullYear() Set the year (optionally month and day) setHours() Set the hour (0-23) setMilliseconds() Set the milliseconds (0- 999) setMinutes() Set the minutes (0-59) setMonth() Set the month (0-11) setSeconds() Set the seconds (0-59) setTime() Set the time (milliseconds since January 1, 1970)
  • 19. The setDate() Method setDate() sets the day of the month (1-31): <!DOCTYPE html> <html> <body> <p>The setDate() method sets the date of a month.</p> <p id="demo"></p> <script> var d = new Date(); d.setDate(15); document.getElementById("demo").innerHTML = d; </script> </body> </html>
  • 20. The setDate() Method The setDate() method can also be used to add days to a date: <!DOCTYPE html> <html> <body> <p>The setDate() method can be used to add days to a date.</p> <p id="demo"></p> <script> var d = new Date(); d.setDate(d.getDate() + 50); document.getElementById("demo").innerHTML = d; </script> </body> </html>
  • 21. JavaScript Math Object • The JavaScript Math object allows you to perform mathematical tasks on numbers. • Example Math.PI; • Math.round() ▫ Math.round(x) returns the value of x rounded to its nearest integer: • Example Math.round(4.7); // returns 5 Math.round(4.4); // returns 4
  • 22. Math Properties (Constants) • JavaScript provides 8 mathematical constants that can be accessed with the Math object: • Example  Math.E // returns Euler's number  Math.PI // returns PI  Math.SQRT2 // returns the square root of 2  Math.SQRT1_2 // returns the square root of ½  Math.LN2 // returns the natural logarithm of 2  Math.LN10 // returns the natural logarithm of 10  Math.LOG2E // returns base 2 logarithm of E  Math.LOG10E // returns base 10 logarithm of E
  • 23. JavaScript Math Object Method: Round() <!DOCTYPE html> <html> <body> <h1>JavaScript Math.round()</h1> <p>Math.round(x) returns the value of x rounded down to its nearest integer:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.round(4.4); </script> </body> </html>
  • 24. JavaScript Math Object: pow() <!DOCTYPE html> <html> <body> <h1>JavaScript Math.pow()</h1> <p>Math.pow(x,y) returns the value of x to the power of y:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.pow(8,2); </script> </body> </html>
  • 25. JavaScript Math Object: sqrt() <!DOCTYPE html> <html> <body> <h1>JavaScript Math.sqrt()</h1> <p>Math.sqrt(x) returns the square root of x:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.sqrt(64); </script> </body> </html>
  • 26. JavaScript Math Object: abs() <!DOCTYPE html> <html> <body> <h1>JavaScript Math.abs()</h1> <p>Math.abs(x) returns the absolute (positive) value of x:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.abs(-4.4); </script> </body> </html>
  • 27. JavaScript Math Object: abs() <!DOCTYPE html> <html> <body> <h1>JavaScript Math.abs()</h1> <p>Math.abs(x) returns the absolute (positive) value of x:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Math.abs(-4.4); </script> </body> </html>
  • 28. Math Object Methods Method Description abs(x) Returns the absolute value of x acos(x) Returns the arccosine of x, in radians asin(x) Returns the arcsine of x, in radians atan(x) Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians atan2(y, x) Returns the arctangent of the quotient of its arguments ceil(x) Returns the value of x rounded up to its nearest integer cos(x) Returns the cosine of x (x is in radians) exp(x) Returns the value of E x floor(x) Returns the value of x rounded down to its nearest integer log(x) Returns the natural logarithm (base E) of x max(x, y, z, ..., n) Returns the number with the highest value min(x, y, z, ..., n) Returns the number with the lowest value pow(x, y) Returns the value of x to the power of y random() Returns a random number between 0 and 1 round(x) Returns the value of x rounded to its nearest integer sin(x) Returns the sine of x (x is in radians) sqrt(x) Returns the square root of x tan(x) Returns the tangent of an angle
  • 29. Number Methods and Properties Property Description MAX_VALUE Returns the largest number possible in JavaScript MIN_VALUE Returns the smallest number possible in JavaScript NEGATIVE_INFI NITY Represents negative infinity (returned on overflow) NaN Represents a "Not-a-Number" value POSITIVE_INFIN ITY Represents infinity (returned on overflow)
  • 30. Number Properties <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Number.MAX_VALUE; </script> </body> </html>
  • 31. Number Methods • The toString() Method ▫ toString() returns a number as a string. • The toExponential() Method ▫ toExponential() returns a string, with a number rounded and written using exponential notation. • The toFixed() Method ▫ toFixed() returns a string, with the number written with a specified number of decimals: • The toPrecision() Method ▫ toPrecision() returns a string, with a number written with a specified length: • The valueOf() Method ▫ valueOf() returns a number as a number.
  • 32. The toFixed() Method <!DOCTYPE html> <html> <body> <p>The toFixed() method rounds a number to a given number of digits.</p> <p>For working with money, toFixed(2) is perfect.</p> <p id="demo"></p> <script> var x = 9.656; document.getElementById("demo").innerHTML = x.toFixed(0) + "<br>" + x.toFixed(2) + "<br>" + x.toFixed(4) + "<br>" + x.toFixed(6); </script> </body> </html>
  • 33. Converting Variables to Numbers • There are 3 JavaScript methods that can be used to convert variables to numbers: ▫ The Number() method ▫ The parseInt() method ▫ The parseFloat() method • These methods are not number methods, but global JavaScript methods. Method Description Number() Returns a number, converted from its argument. parseFloat() Parses its argument and returns a floating point number parseInt() Parses its argument and returns an integer
  • 34. The parseInt() Method parseInt() parses a string and returns a whole number. Spaces are allowed. Only the first number is returned: <!DOCTYPE html> <html> <body> <p>The global JavaScript function parseInt() converts strings to numbers:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = parseInt("10") + "<br>" + parseInt("10.33") + "<br>" + parseInt("10 6") + "<br>" + parseInt("10 years") + "<br>" + parseInt("years 10"); </script> </body> </html>
  • 35. JavaScript Regular Expressions • A regular expression is a sequence of characters that forms a search pattern. • When you search for data in a text, you can use this search pattern to describe what you are searching for. • A regular expression can be a single character, or a more complicated pattern. • Regular expressions can be used to perform all types of text search and text replace operations. • Syntax /pattern/modifiers;
  • 36. Using String Methods With a Regular Expression • In JavaScript, regular expressions are often used with the two string methods: search() and replace(). • The search() method uses an expression to search for a match, and returns the position of the match. • The replace() method returns a modified string where the pattern is replaced.
  • 37. Use String replace() With a Regular Expression <!DOCTYPE html> <html> <body> <p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p> <button onclick="myFunction()">Try it</button> <p id="demo">Please visit Microsoft!</p> <script> function myFunction() { var str = document.getElementById("demo").innerHTML; var txt = str.replace("Microsoft","W3Schools"); document.getElementById("demo").innerHTML = txt; } </script> </body> </html>