Vineeth.mariserla has Published 278 Answers

How to add an event handler to the specified element in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 30-Jun-2020 09:06:03

Javascript provides the addEventListener() method that attaches an event handler to the specified element. This method attaches an event handler to an element without overwriting existing event handlers. At a time it is possible to add many event handlers to an element.The addEventListener() method makes it easier to control how the ... Read More

Is it possible to change the HTML content in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 30-Jun-2020 08:52:32

Yes, it is possible to change the content of the HTML in javascript. Usually HTML content will be in HTML tags such as <p>, <span>, etc. In javascript, we have DOM methods that have an ability to access the HTML tags. Those methods, such as document.getElementById(), document.getElementByTagName(), etc., make use ... Read More

How to convert a string to a floating point number in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 30-Jun-2020 08:43:31

Javascript has provided a method called parseFloat() to convert a string into a floating point number. Floating numbers are nothing but decimals. We also have another method called parseInt() to do the same task but it will not deal with decimals. It returns only integers.ParseFloat() can change a number string into ... Read More

How to remove false values from an array in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 30-Jun-2020 08:03:47

Javascript library underscore.js has provided _.compact() method to remove all the false values in an array. The false values in an array are nothing but NaN, undefined, empty string, false and 0. It returns a new array that is free from false values as output.syntax_.compact( array );It takes an array as a parameter ... Read More

How to compare two objects in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 30-Jun-2020 07:59:40

Objects are not like arrays or strings. So simply comparing by using "===" or "==" is not possible. Here to compare we have to first stringify the object and then using equality operators it is possible to compare the objects. In the following example, objects were stringified() at first and then compared with each other.ExampleLive Demo<html> ... Read More

Explain exponentiation operator in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 30-Jun-2020 07:43:59

Using Exponentiation operator we can find a number to the power of another number. It is denoted by **. We already have Math.pow() method to find a number to the power of another number. But the exponentiation operator(**) is common not only to javascript but also to other languages such as python, ... Read More

How to clone an array using spread operator in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 30-Jun-2020 07:41:29

Cloning is nothing but copying an array into another array. In olden days, the slice() method is used to clone an array, but ES6 has provided spread operator(...) to make our task easy. Lets' discuss both the methods.Cloning using slice() method  ExampleIn the following example slice() method is used to copy the array. slice() is ... Read More

How to get the length of an object in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 29-Jun-2020 15:08:09

The length property is only applicable to arrays and strings. So when we call the length property on an object we will get undefined.ExampleLive Demo<html> <body> <script>    var object = {prop:1, prop:2};    document.write(object.length); </script> </body> </html>OutputundefinedWhereas arrays and strings will display their length when length property is used on them.ExampleLive Demo<html> <body> <script>    var ... Read More

What is the importance of "enumerable" attribute in defining a property in JavaScript object?

vineeth.mariserla

vineeth.mariserla

Updated on 29-Jun-2020 15:04:55

We can define a property of an object using Dot and Bracket notations. There is also another way in which a property called Object.defineProperty() is used to define a property. It usually takes 3 parameters they are object name, property name, property descriptor.syntaxObject.defineProperty(object name, property name, property descriptor)Lets' define a property with this ... Read More

How to select a radio button by default in JavaScript?

vineeth.mariserla

vineeth.mariserla

Updated on 29-Jun-2020 13:50:54

To select a radio button by default we have to check it as true. If it is checked as true then by default it will be autofocused. In the following example, we have only radio buttons and none of them is autofocused.ExampleLive Demo<html>    <form id="radiobuttons" name="radiobutton">       <input id="rad1" value="a" ... Read More

Previous 1 ... 4 5 6 7 8 9 10 ... 28 Next
Advertisements