Found 6704 Articles for Javascript

What is the difference between == and === in JavaScript?

Daniol Thomas
Updated on 18-Sep-2019 08:25:09

745 Views

Double equals (==) is abstract equality comparison operator, which transforms the operands to the same type before making the comparison. For example,4    ==  4        // true '4'  ==  4        //true 4    == '4'       // true 0    == false     // trueTriple equals (===) are strict equality comparison operator, which returns false for different types and different content.For example,4 === 4  // true 4 === '4' // false var v1 = {'value':'key'}; var v2 = {'value': 'key'}; v1 === v2 //false

How to use JavaScript to load a webpage after 5 seconds?

Abhishek
Updated on 25-Nov-2022 07:20:43

12K+ Views

In this tutorial, we learn to use JavaScript to load a webpage after 5 seconds. We use the setTimeout() function in JavaScript to load a webpage after some interval. This function waits for some seconds and then loads the web page. We could also apply the setInterval() method to perform our task. Generally, a web page loads immediately if the network connection to which user connected is very strong, and if the network connection is very poor, then it will take some time to load. But did you know that, we can stop the web page loading for some time ... Read More

How to validate URL address in JavaScript?

Shubham Vora
Updated on 23-Nov-2022 13:50:26

2K+ Views

In this tutorial, let us discuss how to validate URL addresses in JavaScript. A URL or Uniform Resource Locator identifies web pages, images, and videos on the internet. URLs are website addresses that transfer files, send emails, and many more. URLs consist of a protocol, domain name, and so on. URL indicates how the browser gets the data and where to get the data. We use a URL in the anchor tags or buttons to navigate the user to another location. We must verify the URL's validity before using it. URL Rule URL must start with http:// or https://. ... Read More

How to load a JavaScript function using the variable name?

Shubham Vora
Updated on 15-Sep-2022 12:26:54

996 Views

In this tutorial, we will learn to load a JavaScript function using the name of a variable. Functions are the block of statements that takes an input and displays the result to the user after an execution. We can use these blocks of codes repeatedly by only declaring the function, and these functions can help a programmer in many ways as it also reduces efforts. JavaScript also supports the use of functions like other programming languages. Functions in JavaScript can be either built-in or user-defined. There are different ways to declare a function and call it. Generally, a simple Function ... Read More

How to use JavaScript to hide a DIV when the user clicks outside of it?

Rishi Raj
Updated on 18-Sep-2019 08:30:50

987 Views

To hide a div when the user clicks outside of it, try to run the following codeExampleLive Demo                    window.onload = function(){             var hideMe = document.getElementById('hideMe');             document.onclick = function(e){                if(e.target.id !== 'hideMe'){                   hideMe.style.display = 'none';                }             };          };             Click outside this div and hide it.    

What is the difference between decodeURIComponent and decodeURI?

Vikyath Ram
Updated on 16-Jun-2020 11:03:12

226 Views

decodeURIComponentTo decode a URL component in JavaScript, use the decodeURLComponent() method.ExampleYou can try to run the following code to decode a URL component −           Check                      function display() {             var uri = "http://example.com/welcome msg.jsp?name=åmit&sub=programming";             // first encode             var encode = encodeURIComponent(uri);             var decode = decodeURIComponent(encode);             var result = "Encode= " + ... Read More

What is the difference between single and double quotes in JavaScript?

Kumar Varma
Updated on 16-Jun-2020 11:02:43

118 Views

In JavaScript, use any of the single or double quotes for a string. However, you should be consistent in whatever you select. Single and double quotes are the same in JavaScript −"Let us say: \"Life's good!\"" 'Let us say: "Life\'s good!"' “Let us say: \"Life\'s good!\"" 'Let us say: \"Life\'s good!\"'Let’s see an example, which is supported by ES6 −`Will you be "my" friend. I really liked it when I was a kid,.`;

How to write a JavaScript function to get the difference between two numbers?

Arjun Thakur
Updated on 08-Jan-2020 06:46:47

7K+ Views

Use Math.abs() inside a JavaScript function to get the difference between two numbers in JavaScript.ExampleYou can try to run the following code to get the difference of numbersLive Demo                    var num1, num2;          num1 = 50;          num2 = 35;          var difference = function (num1, num2){             return Math.abs(num1 - num2);          }          document.write("Difference = "+difference(num1,num2));              

What does the operator || do in a var statement in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:40:20

135 Views

In this tutorial, we will discuss what the operator || does in a var statement in JavaScript. The logical OR operator or logical disjunction on the operands returns true if any of the operand values are true, false, ’’, null, undefined, 0, and NaN are the false values. All other values are true. The logical OR operands must be either boolean, integer, or a pointer kind. The logical OR returns the latest operand if there is no true value. The logical OR executes from left to right. Users can follow the syntax below for using the logical OR operator. Syntax ... Read More

What is the purpose of a self-executing function in JavaScript?

Fendadis John
Updated on 12-Jun-2020 12:08:10

324 Views

The purpose of a self-executing is that those variables declared in the self-executing function are only available inside the self-executing function.Variables declared in the self-executing function are, by default, only available to code within the self-executing function.It is an immediately invoked function expression (IIFE). It is a function, which executes on creation.SyntaxHere is the syntax −(function() {    // code })();As you can see above, the following pair of parentheses converts the code inside the parentheses into an expression:function(){...}In addition, the next pair, i.e. the second pair of parentheses continues the operation. It calls the function, which resulted from the ... Read More

Advertisements