Found 6710 Articles for Javascript

How does Exceptions Handling work in JavaScript?

Vrundesha Joshi
Updated on 22-Jun-2020 14:38:52

239 Views

JavaScript uses try…catch…finally to handle exceptions. The latest versions of JavaScript added exception-handling capabilities. JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions.You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors.SyntaxHere is the try...catch...finally block syntax −     ExampleYou can try to run the following code to learn how exceptions are handled in JavaScript −                                         Click the following to see the result:                          

What are Self-Invoking Anonymous Functions in JavaScript?

Rishi Rathor
Updated on 22-Jun-2020 14:39:42

454 Views

In JavaScript, the functions wrapped with parenthesis are called “Immediately Invoked Function Expressions" or "Self Executing Functions.The purpose of wrapping is to the namespace and control the visibility of member functions. It wraps the code inside a function scope and decreases clashing with other libraries. This is what we call Immediately Invoked Function Expression (IIFE) or Self Executing Anonymous Function.SyntaxHere’s 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. ... Read More

How to define a JavaScript function using Function() Constructor?

Nikitha N
Updated on 22-Jun-2020 14:42:23

202 Views

The Function() constructor expects any number of string arguments. The last argument is the body of the function - it can contain arbitrary JavaScript statements, separated from each other by semicolons.ExampleYou can try to run the following code to invoke a function with new Function Constructor −                    var func = new Function("x", "y", "return x*y;");          function multiplyFunction(){             var result;             result = func(15,35);             document.write ( result );          }                     Click the following button to call the function                          

What are different ways of defining functions in JavaScript?

Shubham Vora
Updated on 15-Nov-2022 09:27:24

908 Views

In this tutorial, we will learn the different ways of defining functions in JavaScript. In programming, writing the same code again and again is not a great idea. It will increase the length and decrease the readability with more effort required for the program. The functions are there in the programming languages to make it easier for programmers. The function is like a container containing certain lines of programs inside. The function does not execute by only defining it. We have to call it somewhere in the program by which it can run the code it consists of. We can ... Read More

What are optional arguments in JavaScript Functions?

Daniol Thomas
Updated on 22-Jun-2020 14:42:54

252 Views

To declare optional function parameters in JavaScript, use the “default” arguments.ExampleYou can try to run the following code to declare optional parameters −                    // default is set to 1          function inc(val1, inc = 1) {             return val1 + inc;          }          document.write(inc(10,10));          document.write("");          document.write(inc(10));          

What does “use strict” do in JavaScript, and what is the reasoning behind it?

Shubham Vora
Updated on 31-Oct-2022 11:42:23

269 Views

In this tutorial, we will learn what "use strict" does in JavaScript. The "use strict" is a directive. JavaScript 1.8.5 is its origin. The use strict directive says that the JavaScript code must run in the strict mode. The strict directive is not a statement but rather a constant expression. Earlier JavaScript versions ignore this expression. We can't use undeclared variables when writing the code in strict mode. Except for IE9 and lower versions, all modern browsers support this JavaScript directive. Strict mode allows us to write a cleaner code as it throws errors when we use undeclared variables in ... Read More

JavaScript function definition in Chrome? How can I find it?

Giri Raju
Updated on 22-Jun-2020 14:33:58

4K+ Views

To find the JavaScript function definition in Google Chrome, open the web browser and press F12 to reach Developer Tools.Now press Ctrl + Shift + FCheck Regular Expression as shown below −Search for function and that’s it.

How to remove an item from JavaScript array by value?

Shubham Vora
Updated on 06-Sep-2022 14:24:47

531 Views

In this tutorial, we will learn to remove an item from a JavaScript array by value. An array is a data structure that can store a collection of data with the same data type. A contiguous memory location is allocated to the array elements. Each array element is identified by its index value. You must process an array by inserting an element, removing or changing, etc. JavaScript has a lot of methods to update an array. Let us take a look at various ways to remove an item from a JavaScript array by value. Following are the Methods/Functions to remove ... Read More

How to find duplicate values in a JavaScript array?

Abhishek
Updated on 02-Sep-2023 10:47:49

72K+ Views

In this tutorial, we will discuss how we can find duplicate or repeating values in a JavaScript array using different methods or approaches to reach the solution to this problem. Below is the list of the approaches or methods we can use to solve the problem of finding duplicates − By simply Traversing the Array Using the filter() and indexOf() Methods Using the Set object and has() Method Let us discuss all of the above approaches to find duplicates in the JavaScript array − By Simply Traversing the Array Traversing the array using a nested for loop to ... Read More

How to create a two dimensional array in JavaScript?

Nikitha N
Updated on 19-Jun-2020 13:21:23

734 Views

A two-dimensional array has more than one dimension, such as myarray[0][0] for element one, myarray[0][1] for element two, etc. To create a two-dimensional array in JavaScript, you can try to run the following code −ExampleLive Demo                                        var myarray=new Array(3);                  for (i=0; i

Advertisements