Found 10878 Articles for Web Development

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

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

147 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

3K+ 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

391 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

62K+ 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

510 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

How to find the min/max element of an Array in JavaScript?

Abhishek
Updated on 31-Oct-2022 08:00:31

10K+ Views

In this tutorial, we will learn different ways of finding the maximum and minimum elements of an array in JavaScript. The minimum element is the smallest element among all the elements present in the array, while the maximum is the largest among them Below are the approaches we can use to find the min/max elements of an array. Traverse the whole Array Using the Math.min() and Math.max() Methods. Let us discuss these approaches with help of program examples. Approach 1: Traverse the whole Array In this approach, we will traverse the whole array using the for loop and ... Read More

How does JavaScript 'return' statement work?

Shubham Vora
Updated on 22-Jul-2022 13:06:08

1K+ Views

In this article, we will learn how to work with a return statement in JavaScript. A specific value from the function is returned to the function caller using the return statement. Whenever the return statement is run, the function will stop. The code that follows the return statement won't be available, due to which it is the last statement in a function.Using the return statement, we may return object types, including functions, objects, arrays, and primitive values like Boolean, integer, and string.By using the return statement, we can also return many items. Immediate action is not viable. To return several ... Read More

How to return a string from a JavaScript function?

Nitya Raut
Updated on 19-Jun-2020 11:43:44

14K+ Views

To return a string from a JavaScript function, use the return statement in JavaScript.ExampleYou need to run the following code to learn how to return a string using return statement −                    function concatenate(name, subject) {             var val;             val = name + subject;             return val;          }          function DisplayFunction() {             var result;             result = concatenate('Amit', ' Java');             document.write (result );          }                         Click the following button to call the function                          

How to return a value from a JavaScript function?

Srinivas Gorla
Updated on 19-Jun-2020 11:31:35

2K+ Views

To return a value from a JavaScript function, use the return statement in JavaScript. You need to run the following code to learn how to return a value −Example                    function concatenate(name, age) {             var val;             val = name + age;             return val;          }          function DisplayFunction() {             var result;             result = concatenate('John ', 20) ;             document.write (result );          }                     Click the following button to call the function                          

What is the difference between "strict" and "non-strict" modes of JavaScript?

Abhinanda Shri
Updated on 16-Jan-2020 10:27:46

827 Views

The “use strict” is a directive, which is a literal expression. It introduced in JavaScript 1.8.5. As the name suggests, “use strict” indicates that the code is to be executed in strict mode. Under non-strict, the code won’t execute won’t execute in strict mode.Let us declare strict mode. To declare, add the keyword “use strict” in the beginning. For global scope, declare it at the beginning of the script.           An error would come, since you have used a variable, but forgot to declare it       Press F8 to see the error.                "use strict";          a = 1;          

Advertisements