Javascript Articles

Page 4 of 534

JavaScript One fourth element in array

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 181 Views

ProblemJavaScript function that takes in an array of integers sorted in increasing order, arr.There is exactly one integer in the array that occurs more than one fourth times (25%) of the times, our function should return that number.For example, if the input to the function is −const arr = [3, 5, 5, 7, 7, 7, 7, 8, 9];Then the output should be −const output = 7;Exampleconst arr = [3, 5, 5, 7, 7, 7, 7, 8, 9]; const oneFourthElement = (arr = []) => {    const len = arr.length / 4;    const search = (left, right, target, direction = 'left') => {       let index = -1       while (left

Read More

How exactly does <script defer=“defer”> work?\\n

Samual Sam
Samual Sam
Updated on 11-Mar-2026 313 Views

The defer attribute is used to specify that the script execution occurs when the page loads. It is used only for external scripts and is a boolean attribute.ExampleThe following code shows how to use the defer attribute:                 The external file added will load later, since we're using defer    

Read More

What is nodeValue property in JavaScript HTML DOM?

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 333 Views

The nodeValue property is used to get the node value. You need to specify the node.ExampleYou can try to run the following code to learn how to get nodeValue property.           Get the node value       Demo Button Text                var val = document.getElementsByTagName("BUTTON")[0];          var res = val.childNodes[0].nodeValue;          document.write("Node Value: "+res);          

Read More

How -Infinity is converted to Number in JavaScript?

Monica Mona
Monica Mona
Updated on 11-Mar-2026 261 Views

Use the Number() method in JavaScript to convert to Number. You can try to run the following code to learn how to convert -Infinity Number in JavaScript.Example           Convert -Infinity to Number                var myVal = -Infinity;          document.write("Number : " + Number(myVal));           OutputConvert -Infinity to Number Number : -Infinity

Read More

What will happen when [50,100] is converted to Number in JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 11-Mar-2026 159 Views

Use the Number() method in JavaScript to convert to Number. You can try to run the following code to learn how to convert [50, 100] to Number in JavaScript − Example Live Demo Convert [50,100] to Number var myVal = [50,100]; document.write("Number: " + Number(myVal));

Read More

How to use JavaScript to set cookies for homepage only?

Vrundesha Joshi
Vrundesha Joshi
Updated on 11-Mar-2026 368 Views

To set cookies for a homepage, add the page to the homepage itself.ExampleYou can try to run the following code to set cookies                                                  Enter name:                    

Read More

How to show image in alert box using JavaScript?

Nancy Den
Nancy Den
Updated on 11-Mar-2026 2K+ Views

To show an image in alert box, try to run the following code. Here, an alert image is added to the custom alert box −Example                                function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function() {                confirmBox.hide();             });             confirmBox.find(".yes").click(myYes);           ...

Read More

How to customize the position of an alert box using JavaScript?

mkotla
mkotla
Updated on 11-Mar-2026 3K+ Views

To customize the position of an alert box, use the CSS “top” and “left” properties. We have a custom alert box, which we’ve created using jQuery and styled with CSS.ExampleYou can try to run the following code to customize the position of an alert box −                          function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function() {                confirmBox.hide();     ...

Read More

Why does the JavaScript void statement evaluate an expression?

Giri Raju
Giri Raju
Updated on 11-Mar-2026 142 Views

The JavaScript void returns an expression to remove the side effect and return the undefined primitive value. This side effect may occur while inserting expression in a web page.Let’s see an example of the void. The void(0) can be used with hyperlinks to obtain the undefined primitive value, Example                    Understanding JavaScript void(0)                 Click me not once, but twice.     We used JavaScript:void(0) above to prevent the page from reloading when the button is clicked the first time.The code will only ...

Read More

What is the difference between an acronym and abbr tags?

mkotla
mkotla
Updated on 11-Mar-2026 789 Views

In layman language, an acronym is a word formed by taking letters of each word in a phrase to form an abbreviation. Acronyms are a subset of abbreviations i.e. abbreviation is a shortened form of a word.The tag isn’t supported in HTML5 and is deprecated now. Do not use. To add abbreviation in HTML, use the tag. Both abbreviation and acronym are the shortened versions and are represented as a series of letters. Some of the examples include, "Mr.", "IST", "MRI", “NASA”, “ISRO” etc. ExampleYou can try to run the following code to add abbreviation in HTML.   ...

Read More
Showing 31–40 of 5,339 articles
« Prev 1 2 3 4 5 6 534 Next »
Advertisements