Getelementbyid
Getelementbyid
Brendan Eich is an
American computer programmer and technology executive. He created the
JavaScript programming language
What is JavaScript
2.Features of JavaScript:
a = b = 3, c = 4;
delete Delete Operator deletes a property from the object.
The delete operator deletes both the value of the property and the property
itself.
E.g : object
let human = {
name: "John Doe",
age: 15,
country: "Japan"}
delete human["country"]
in this operator checks if object has the given property
instanceof checks if the object is an instance of given type
E.g:
const auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car);
// Expected output: true
The JavaScript date object can be used to get year, month and day. You
can display a timer on the webpage by the help of JavaScript date object.
You can use different Date constructors to create date object. It provides
methods to get and set day, month, year, hour, minute and seconds.
Constructor
Use of Date constructor to create date object.
Date()
JavaScript Date Example:-
Let's see the simple example to print date object. It prints date and time
both.
The <span> tag is an inline container used to mark up a part of a text, or
a part of a document. The <span> tag is easily styled by CSS or manipulated
with JavaScript using the class or id attribute. The <span> tag is much like the
<div> element, but <div> is a block-level element and <span> is an inline
element.
<html>
<body>
Current Date and Time: <span id="txt"></span>
<script>
var today=new Date();
document.getElementById('txt').innerHTML=today;
</script>
</body>
</html>
O/P:-
Let's see the list of JavaScript date methods with their description.
Methods Description
12.JavaScript Math:-
Math.sqrt(n)
The JavaScript math.sqrt(n) method returns the square root of the given
number.
<!DOCTYPE html>
<html>
<body>
Square Root of 17 is: <span id="p1"></span>
<script>
document.getElementById('p1').innerHTML=Math.sqrt(17);
</script>
</body>
</html>
Math.random()
The JavaScript math.random() method returns the random number between 0
to 1.
<!DOCTYPE html>
<html>
<body>
Random Number is: <span id="p2"></span>
<script>
document.getElementById('p2').innerHTML=Math.random();
</script>
</body>
</html>
Math.floor(n)
The JavaScript math.floor(n) method returns the lowest integer for the
given number. For example 3 for 3.7, 5 for 5.9 etc.
<!DOCTYPE html>
<html>
<body>
Floor of 4.6 is: <span id="p4"></span>
<script>
document.getElementById('p4').innerHTML=Math.floor(4.6);
</script>
</body>
</html>
Math.ceil(n)
The JavaScript math.ceil(n) method returns the largest integer for the
given number. For example 4 for 3.7, 6 for 5.9 etc.
<!DOCTYPE html>
<html>
<body>
Ceil of 4.6 is: <span id="p5"></span>
<script>
document.getElementById('p5').innerHTML=Math.ceil(4.6);
</script>
</body>
</html>
Math.round(n)
The JavaScript math.round(n) method returns the rounded integer nearest
for the given number. If fractional part is equal or greater than 0.5, it goes to
upper value 1 otherwise lower value 0. For example 4 for 3.7, 3 for 3.3, 6 for 5.9
etc.
<!DOCTYPE html>
<html>
<body>
Round of 4.3 is: <span id="p6"></span><br>
Round of 4.7 is: <span id="p7"></span>
<script>
document.getElementById('p6').innerHTML=Math.round(4.3);
document.getElementById('p7').innerHTML=Math.round(4.7);
</script>
</body>
</html>
Math.abs(n)
The JavaScript math.abs(n) method returns the absolute value for the given
number. For example 4 for -4, 6.6 for -6.6 etc.
<!DOCTYPE html>
<html>
<body>
Absolute value of -4 is: <span id="p8"></span>
<script>
document.getElementById ('p8').innerHTML=Math.abs (-4);
</script>
</body>
</html>