All Questions (625 questions)



How to get a JavaScript object’s class?

Posted by Editorial Staff | Updated on

If you want to get a JavaScript object’s class? There’s no exact counterpart to Java’s getClass() in JavaScript. Mostly that’s due to JavaScript being a prototype-based language, as opposed to Java being a class-based one. …

How to check if a string is html or not using JavaScript?

Posted by Rohit Kumar | Updated on

Want to check if a string is html or not using JavaScript? Use the following example: check if a string is html or not using JavaScript The task is to validate whether the given string …

How do you implement a Stack and a Queue in JavaScript?

Posted by Prem Tiwari | Updated on

Want to implement a Stack and a Queue in JavaScript? Lets see an example of an stack class using array in Java script.

How do I check that a number is float or integer?

Posted by Editorial Staff | Updated on

There is a method called Number.isInteger() which is currently implemented in everything but IE. MDN also provides a polyfill for other browsers: However, for most uses cases, you are better off using Number.isSafeInteger which also checks if the value …

How many types of error in JavaScript?

Posted by Ramesh Singh | Updated on

In this answer, I have shared how many types of error in JavaScript. Following are the JavaScript errors: The try statement lets you test a block of code for errors. The catch statement lets you handle the error. The throw statement …

How to write switch statements multiple cases in JavaScript?

Posted by Rohit Kumar | Updated on

Want to write switch statements multiple cases in JavaScript? Use the fall-through feature of the switch statement. A matched case will run until a break (or the end of the switch statement) is found, so …

Include jQuery in the JavaScript Console

Posted by Ramesh Singh | Updated on

Run this in your browser’s JavaScript console, then jQuery should be available.

Getting a random value from a JavaScript array?

Posted by Ramesh Singh | Updated on

Are you want to get the random value from an array using JavaScript. There are more options, following are some JavaScript functions: Use Math. random() function to get the random number between(0-1, 1 exclusive). Multiply it by the array length to get the numbers between(0-arrayLength). …

How to get the browser viewport dimensions?

Posted by Editorial Staff | Updated on

Want to get the browser viewport dimensions? Use the following example to get the browser viewport height and width. Cross-browser @media (width) and @media (height) values window.innerWidth and .innerHeight gets CSS viewport @media (width) and @media (height) which include scrollbars initial-scale and zoom variations may …

Function overloading in JavaScript?

Posted by Prem Tiwari | Updated on

In this example, I have shared function overloading in JavaScript? The best way to do function overloading with parameters is not to check the argument length or the types; checking the types will just make …

How to make an AJAX call without jQuery?

Posted by Prem Tiwari | Updated on

Want to make an AJAX call without jQuery? You can do using “vanilla” JavaScript. Following is an example to make an AJAX call without jQuery. Make an AJAX call using jQuery

How to get the Value in an Input Text Box using jQuery?

Posted by Ramesh Singh | Updated on

Want to get the Value in an Input Text Box using jQuery? Use the jQuery val() Method. Following is an example to get the Value in an Input Text Box.

How to get the text inside an element using jQuery?

Posted by Ramesh Singh | Updated on

Answer: Use the jQuery text() method If you want to get the text inside an element using jQuery? Use the following jQuery example to get the text inside an element.

How can you encode a string to Base64 in JavaScript?

Posted by Ramesh Singh | Updated on

If you want encode a string to Base64 in JavaScript? You can use btoa() and atob() to convert to and from base64 encoding. There appears to be some confusion in the comments regarding what these functions accept/return: btoa() accepts …

How to add scroll to bottom of div using JavaScript?

Posted by Pinki | Updated on

Want to add scroll to bottom of div using JavaScript? Use the following JavaScript example to add scroll to bottom of div in your website. Here’s what I use on my site: