Category: JavaScript Misc
-
JavaScript prompt() dialog box
The prompt() method in JavaScript is used to display a prompt box that prompts the user for the input. It is generally used to take the input from the user before entering the page. It can be written without using the window prefix. When the prompt box pops up, we have to click “OK” or “Cancel” to proceed. The…
-
JavaScript hide elements
In JavaScript, we can hide the elements using the style.display or by using the style.visibility. The visibility property in JavaScript is also used to hide an element. The difference between the style.display and style.visibility is when using visibility: hidden, the tag is not visible, but space is allocated. Using display: none, the tag is also not visible, but there is no space allocated on the page. In HTML, we…
-
JavaScript getAttribute() method
The getAttribute() method is used to get the value of an attribute of the particular element. If the attribute exists, it returns the string representing the value of the corresponding attribute. If the corresponding attribute does not exist, it will return an empty string or null. It is different from the getAttributeNode() method. The getAttributeNode() method returns the attribute as an…
-
JavaScript continue statement
There is full control to handle loop statements in JavaScript. Sometimes, a situation occurs when we require to skip some code of the loop and move to the next iteration. It can be achieved by using JavaScript’s continue statement. The continue statement in JavaScript is used to jumps over an iteration of the loop. Unlike the break statement, the continue statement breaks the…
-
JavaScript eval() function
The eval() function in JavaScript is used to evaluate the expression. It is JavaScirpt’s global function, which evaluates the specified string as JavaScript code and executes it. The parameter of the eval() function is a string. If the parameter represents the statements, eval() evaluates the statements. If the parameter is an expression, eval() evaluates the expression. If the parameter…
-
JavaScript alert()
The alert() method in JavaScript is used to display a virtual alert box. It is mostly used to give a warning message to the users. It displays an alert dialog box that consists of some specified message (which is optional) and an OK button. When the dialog box pops up, we have to click “OK” to proceed.…
-
JavaScript array.length property
The length property returns the number of elements in an array in the form of a 32-bit unsigned integer. We can also say that the length property returns a number that represents the number of array elements. The return value is always larger than the highest array index. The length property can also be used to set the number…
-
Javascript Compare dates
In the previous section, we discussed the date methods as well as the constructors. Here, with the help of those methods, we will learn to compare dates. Basically, there are different ways by which we can compare dates, such as: Comparing two dates with one another Example: Comparing date with time Example 1: Comparing different dates…
-
JavaScript Promise
Promises in real-life express a trust between two or more persons and an assurance that a particular thing will surely happen. In javascript, a Promise is an object which ensures to produce a single value in the future (when required). Promise in javascript is used for managing and tackling asynchronous operations. Need for JavaScript Promise…
-
JavaScript Strict Mode
Being a scripting language, sometimes the JavaScript code displays the correct result even it has some errors. To overcome this problem we can use the JavaScript strict mode. The JavaScript provides “use strict”; expression to enable the strict mode. If there is any silent error or mistake in the code, it throws an error. Note…