Object is a real world thing or entity.Object can call any method and access attributes also.
Method Accessing
Attributes Accessing
Object. Method Name(Parameters);
Object. Property name=value;
Java Script Objects
S.No
Object Name
1
Window
2
Document
3
String
4
Console
5
Number
6
Arrays
7
Date
8
Math
Window Properties
Property
Details
screenX
Returns the horizontal coordinate of the window relative to the screen
screenY
Returns the vertical coordinate of the window relative to the screen
Window Methods
Method
Example
Details
open()
window.open("https://www.w3schools.com");
Open a new window.
prompt
window.prompt("Enter no1")
Asks for data as input.
alert
window.prompt("Enter no1")
Displays the data.
close()
window.close();
close the current window.
Program
Output
Enter no1 4
Enter no2 5
sum 9
Document Properties
Attribute
Example
bgColor
document.bgColor =”blue”;
document.body.style.backgroundColor
document.body.style.backgroundColor="blue";
document.fgColor
document.fgColor = "yellow";
document.linkColor
document.linkColor="yellow";
Document Methods
Methods
Details
Writes HTML expressions or JavaScript code to a document
Same as write(), but adds a newline character after each statement
Example: 1. Write a program to add 2 numbers.
Program
Output
Add Numbers
5+5
Try it
10
String
1. It is a collection of characters.
2. It can be any text inside double or single quotes. Example: var mystr = "abcd 1234";
Method
Description
length
Returns the length of a string.
Example
Var a = parseInt(textboxname.length); document.f1.t4.value = parseInt(t1.length);
charAt()
Returns character at
the specified index (position)
concat()
Joins 2 / more strings,
and returns a new joined strings
endsWith()
Checks whether a string ends with specified string/characters
includes()
Checks whether a string
contains the specified string/characters
indexOf()
Returns the position of
the first found occurrence of a specified value in a string
lastIndexOf()
Returns the position of
the last found occurrence of a specified value in a string
match()
Searches a string for a
match against a regular expression, and returns the matches
replace()
Searches a string for a
specified value, or a regular expression, and returns a new string where the
specified values are replaced
search()
Searches a string for a
specified value, or regular expression, and returns the
position of the match
split()
Splits a string into an array of substrings
startsWith()
Checks whether a string
begins with specified characters
substr()
Extracts the characters
from a string, beginning at a specified start position, and
through the specified
number of character.
substring()
Extracts the characters
from a string, between two specified indices
toLowerCase()
Converts a string to
lowercase letters
toString()
Returns the value of a String object
toUpperCase()
Converts a string to
uppercase letters
trim()
Removes whitespace from
both ends of a string
Number Object
Program
Output
Adition Program
12345
Converting Variables to Numbers
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
Arrays
It collections of element all are of same data type.Number of elements are
indicated by index of an array
Program
output
JavaScript Arrays
ab, cd, ef
JavaScript Arrays
ab
JavaScript Objects
abcd
JavaScript Date Object
JavaScript Date Object
Year: 2020
Year: 17
Month: 3
Minutes:5
Seconds: 21
Math Object
Math.E // returns Euler's number
Math.PI // returns PI
Math.SQRT2 // returns square root of 2
Math.SQRT1_2 // returns square root of 1/2
Math.LN10 // returns natural logarithm of 10
Math.LOG2E // returns base 2 logarithm of E
Math.LOG10E // returns base 10 logarithm of E
Math.LN2 // returns natural logarithm of 2
Method
Returns the
abs(x)
absolute value of x
acos(x)
arccosine of x, in radians
asin(x)
arcsine of x, in radians
atan(x)
arctangent of x as a numeric value between -PI/2 and PI/2 radians
atan2(y, x)
arctangent of the quotient of its arguments
ceil(x)
value of x rounded up to its nearest integer
floor(x)
value of x rounded down to its nearest integer
exp(x)
value of Ex
log(x)
natural logarithm (base E) of x
max(x, y, z, ..., n)
number with the highest
value
min(x, y, z, ..., n)
number with the lowest value
pow(x, y)
value of x to the power of y
random()
a random number between 0 and 1
round(x)
value of x rounded to its nearest integer
sqrt(x)
square root of x
sin(x)
sine of x
cos(x)
cosine of x (x is in radians)
tan(x)
tangent of an angle
Boolean
It is used to return true or false for a variable on a condition.