Professional Documents
Culture Documents
asfasdfdefaefwfew34r2
asfasdfdefaefwfew34r2
The “onmouseout” event occurs when a user moves the mouse pointer out of the area
occupied by an HTML element like an image, a button, or a hyperlink.
Here’s an example:
It also has an “onmouseout” attribute specified, indicating that when the user
moves the mouse cursor out of the image area, the "hideMessage()" function should
be executed.
Then, when the user moves the mouse cursor out of the image area, a JavaScript
function called “hideMessage()” is called.
The function displays an alert dialog with the message "Mouse left the image area!"
onload Event
The “onload” event executes a function or script when a webpage or a specific
element within the page (such as an image or a frame) has finished loading.
<body onload="initializePage()">
<script>
function initializePage() {
alert("Page has finished loading!");
}
</script>
In this example, when the webpage has fully loaded, the “initializePage()” function
is executed, and an alert with the message "Page has finished loading!" is
displayed.
onfocus Event
The “onfocus” event triggers when an HTML element like an input field receives
focus or becomes the active element of a user’s input or interaction.
It also has an “onfocus” attribute specified. Which indicates that when the user
clicks on the input field or tabs into it, the "handleFocus()" function will be
executed.
This function displays an alert with the message "Input field has received focus!"
The “onfocus” event is commonly used in web forms to provide visual cues (like
changing the background color or displaying additional information) to users when
they interact with input fields.
onsubmit Event
The “onsubmit” event triggers when a user submits an HTML form. Typically by
clicking a "Submit" button or pressing the "Enter" key within a form field.
It allows you to define a function or script that should be executed when the user
attempts to submit the form.
Math.abs() Method
This method returns the absolute value of a number, ensuring the result is
positive.
This method is helpful for scenarios where you need to ensure that a value is non-
negative, regardless of its initial sign.
Math.round() Method
This method rounds a number up to the nearest integer.
Sample code:
This method is commonly used in scenarios when you want to round up quantities,
such as when calculating the number of items needed for a particular task or when
dealing with quantities that can't be fractional.
Math.max() Method
This method returns the largest value among the provided numbers or values. You can
pass multiple arguments to find the maximum value.
The method then returns the largest value from the provided set of numbers, which
is 20 in this case.
This method is commonly used in scenarios like finding the highest score in a game
or the maximum temperature in a set of data points.
Math.min() Method
The “Math.min()” method returns the smallest value among the provided numbers or
values.
Sample code:
The method then returns the smallest value from the given set of numbers, which is
-3.
This method is commonly used in situations like identifying the shortest distance
between multiple points on a map or finding the lowest temperature in a set of data
points.
Math.random() Method
This method generates a random floating-point number between 0 (inclusive) and 1
(exclusive).
let base = 2;
let exponent = 3;
let result = Math.pow(base, exponent);
console.log(`${base}^${exponent} is equal to: ${result}`)
In this code, we have a base value of 2 and an exponent value of 3. By applying
“Math.pow(),” we calculate 2 raised to the power of 3, which is 8.
Math.sqrt() Method
This method computes the square root of a number.
Number.isInteger() Method
This method checks whether a given value is an integer. It returns true if the
value is an integer and false if not.
They allow you to create, manipulate, and format date and time values in your
JavaScript code.
getDate() Method
This method retrieves the current day of the month. The day is returned as an
integer, ranging from 1 to 31.
We then use the “getDate()” method to retrieve the day of the month and store it in
the “dayOfMonth” variable.
getDay() Method
This method retrieves the current day of the week.
The day is returned as an integer, with Sunday being 0, Monday being 1, and so on.
Up to Saturday being 6.
Sample code:
We then use the “getDay()” method to retrieve the day of the week and store it in
the “dayOfWeek” variable.
getMinutes()Method
This method retrieves the minutes portion from the present date and time.
Sample code:
We use the “getMinutes()” method to retrieve the minutes component and store it in
the minutes variable.
getFullYear() Method
This method retrieves the current year. It’ll be a four-digit integer.
We use the “getFullYear()” method to retrieve the year and store it in the year
variable.
setDate() Method
This method sets the day of the month. By changing the day of the month value
within the “date” object.
Sample code:
We use the “setDate()” method to set the day of the month to 15. And the “date”
object is updated accordingly.
Even if your code is error-free, search engines may have trouble rendering your
website content correctly. Which can prevent them from indexing your website
properly.
You can check to see if JS is causing any rendering issues by auditing your website
with Semrush’s Site Audit tool.
Open the tool and enter your website URL. Then, click “Start Audit.”
You’ll see whether certain elements (links, content, title, etc.) are rendered
differently by the browser and the crawler.