Found 6704 Articles for Javascript

How to extract the hostname portion of a URL in JavaScript?

Shubham Vora
Updated on 23-Aug-2022 09:20:54

10K+ Views

In this tutorial, we will see how to extract the hostname portion of a URL in JavaScript. What is a URL? An alternative term for a web address is a URL. For example, tutorialpoints.com is a word-based URL. An IP address can also be used as a URL (ex. 192.168.2.24). Since names are simpler to recall than numbers, most users submit the name’s address when searching on the internet A URL is a method by which web browsers ask web servers for specific pages. The syntax/format of a URL is given below. Syntax scheme://prefix.domain:port/path/filename Parameters scheme − specifies ... Read More

Is it required to have a return a value from a JavaScript function?

George John
Updated on 08-Jan-2020 06:30:25

2K+ Views

A JavaScript function can have an optional return statement i.e. it’s optional to return a value. This statement should be the last statement in a function.For example, you can pass two numbers in a function and then you can expect the function to return their multiplication to your calling program.ExampleTry the following example. It defines a function that takes two parameters and concatenates them before returning the resultant in the calling program.Live Demo                    function concatenate(first, last){          var full;          full = first ... Read More

What is a standard for commenting a function in JavaScript?

Saurabh Jaiswal
Updated on 05-Jan-2023 16:15:47

6K+ Views

JavaScript is used everywhere, from creating the back end using environments like Node.js to creating the front end using React.js, Vue.js, etc. In JavaScript, the uses of a function are very high, it is used for performing a group operation, it is used as a callback, as a constructor, and in many more places. With the high use of functions in JavaScript, the code becomes full of functions everywhere and looks messy and hard to debug. At a point, it is difficult to find which functions trigger which event and which callbacks are used for what, so it is ... Read More

How to call a parent window function from an iframe using JavaScript?

Paul Richard
Updated on 08-Jan-2020 06:27:14

3K+ Views

To call a parent window function, use “window.top”.ExampleYou can try to run the following code to call a parent window function from an iframeLive Demo                    function display(){             alert("Hello World!");          }                      Click          

How to use unlimited arguments in a JavaScript function?

Shubham Vora
Updated on 31-Oct-2022 10:58:12

2K+ Views

In this tutorial, let us discuss the methods to use unlimited arguments in a JavaScript function. The number of arguments in a JavaScript function is a bit tricky. If we specify three arguments should follow the correct order of the arguments. Let us discover the solution to this problem by introducing the methods to pass unlimited in a function, we can not pass more than three. Moreover, we arguments to a JavaScript function. Using ES5 Arguments Object Instead of converting the arguments object to an array, we can process the arguments object with the total number of arguments. Follow the ... Read More

How can I declare optional function parameters in JavaScript?

Shubham Vora
Updated on 12-Jul-2022 14:00:36

10K+ Views

This tutorial will teach us how to declare optional function parameters in JavaScript. While declaring the function, we pass some variables to the function definition to use it inside the function block, called function parameters. The function parameters can also be optional, which gives us the independence to pass function arguments when we call the function. Here, Arguments are the values we pass while calling the function, and parameters are the variables we pass in the function definition.Optional ParametersThe optional parameter word means that you don’t need to pass that parameter every time you call the function, giving you the ... Read More

What is Multiplication Assignment Operator (*=) in JavaScript?

Abhishek
Updated on 08-Nov-2022 06:26:51

379 Views

In this article, we will learn about the Multiplication assignment operator (*=) in JavaScript. In general, we use a = a * b this expression to update the value of a variable with the value returned after multiplying its original value with some other value, which is easy to understand, but it time taking to write again and again if we are using updating values of more variables like this. So, to overcome this problem, JavaScript introduces us to the multiplication assignment operator (*=) as it is the short form for using the above expression. The multiplication Assignment operator (*=) ... Read More

How to delay a JavaScript function call using JavaScript?

Prince Varshney
Updated on 31-Oct-2023 04:49:00

90K+ Views

In this tutorial, we are going to learn how can we delay a function in JavaScript. Whenever we want to call a function after a specified amount of time than we use the delay function in JavaScript. To provide delay in JavaScript function we use a global window object named as setTimeout(). This function allows us to provide a specific delay before executing a function. Let’s deep down into some of the functionalities, syntax and many other things of setTimeout() function. The setTimeout() method mainly require two one is the function which we need to execute with some delay and ... Read More

How to use associative array/hashing in JavaScript?

Abhishek Kumar
Updated on 10-Nov-2022 08:43:54

437 Views

We use Object and Map classes to mimic the behavior of associative array/hashing in JavaScript. JavaScript doesn’t provide an associative array built-in. The closest similar behavior we get is from the Map class in JavaScript. Let us look at them one by one. Object class in JavaScript The object class allows us to create objects with name-value pairs. This is similar to hashing as the object knows which property is associated with what value. Syntax const obj = { name : "Abhishek", age : 22 } var name = obj.name This creates an ... Read More

How to encode a URL using JavaScript function?

Shubham Vora
Updated on 23-Aug-2022 09:12:46

2K+ Views

As we know, a URL is a web address. What is URL encodingand why do we need to encode a URL? The process of turning a string into an accurateURL format is known as URL encoding. A valid URL format only uses "alpha | digit | safe | extra | escape" characters. Only a limited selection of the normal 128 ASCII characters is permitted in URLs. It is required to encrypt reserved characters that are not part of this set. The reliability and security of the URLs are increased with URL encoding. Each character that needs to be URL-encoded is ... Read More

Advertisements