Category: JavaScript Misc
-
JavaScript timer
In JavaScript, a timer is created to execute a task or any function at a particular time. Basically, the timer is used to delay the execution of the program or to execute the JavaScript code in a regular time interval. With the help of timer, we can delay the execution of the code. So, the…
-
JavaScript String trim()
The trim() is a built-in string function in JavaScript, which is used to trim a string. This function removes the whitespace from both the ends, i.e., start and end of the string. As the trim() is a string method, so it is invoked by an instance of the String class. We have to create an…
-
Calculate days between two dates in JavaScript
Sometimes we need to calculate the number of days between two dates. This can be done using the JavaScript programming language. JavaScript provides a math function Math.floor() method to calculate the days between two dates. In JavaScript, we have to use the date object for any calculation to define the date using new Date(). To learn more about JavaScript…
-
Calculate current week number in JavaScript
Sometimes we need to calculate the current week number or the week number for a given date. This problem can be solved using the JavaScript programming language. JavaScript offers several date functions, such as getDays(), getMonth(), getTime(), to solve date-related tasks. Along with that, the math functions Math.floor() and Math.ceil() also help to calculate the week number. Situation In this…
-
JavaScript setAttribute()
The setAttribute() method is used to set or add an attribute to a particular element and provides a value to it. If the attribute already exists, it only set or changes the value of the attribute. So, we can also use the setAttribute() method to update the existing attribute’s value. If the corresponding attribute does not exist, it will…
-
JavaScript reload() method
In JavaScript, the reload() method is used to reload a webpage. It is similar to the refresh button of the browser. This method does not return any value. Syntax This method can have optional parameters true and false. The true keyword force to reload the page from the server, while the false keyword reloads the page from the cache. The false is the default parameter of…
-
JavaScript typeof operator
The JavaScript typeof operator is used to return a string that represents the type of JavaScript for a given value. It returns the data type of the operand in the form of a string. The operand can be a literal or a data structure like a function, an object, or a variable. Syntax There are following two…
-
JavaScript return
The return statement is used to return a particular value from the function to the function caller. The function will stop executing when the return statement is called. The return statement should be the last statement in a function because the code after the return statement will be unreachable. We can return primitive values (such as Boolean, number, string, etc.) and Object types…
-
JavaScript reset
In HTML, we can use the reset button to reset the form. In this article, we are discussing how to reset the form using JavaScript. In JavaScript, the reset() method does the same thing as the HTML reset button. It is used to clear all the values of the form elements. It can be used to set the values to default.…
-
JavaScript removeAttribute() method
This method is used to remove the specified attribute from the element. It is different from the removeAttributeNode() method. The removeAttributeNode() method removes the particular Attr object, but the removeAttribute() method removes the attribute with the specified name. Syntax Parameter Values attributename: It is the required parameter that specifies the attribute’s name to remove from the element. If the attribute doesn’t exist,…