Found 6710 Articles for Javascript

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

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

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

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

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

935 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;          

How to invoke a JavaScript Function with 'new' Function Constructor?

Shubham Vora
Updated on 14-Sep-2022 13:55:26

779 Views

In this tutorial, we will learn how to invoke a JavaScript Function with the 'new' Function Constructor. Functions are a set of reusable codes that perform a specific task and may return a value. In JavaScript, functions are defined by the keyword function. A function may not have any parameters and may also not have any return statement. In JavaScript, we also have functions with no function names, called anonymous functions Using the 'new' Function Constructor The Function constructor makes a new Function object. By using the constructor, we can create a function dynamically. It takes parameters, or arguments, and ... Read More

How to call a function in JavaScript?

Nancy Den
Updated on 19-Jun-2020 11:24:12

1K+ Views

JavaScript allows us to write our own functions as well. To invoke a function somewhere later in the script, you would simply need to write the name of that function.ExampleYou can try to run the following code to learn how to call a function in JavaScript −                    function sayHello() {             document.write ("Hello there!");          }                     Click the following button to call the function                             Use different text in write method and then try...    

How to call a JavaScript function on click?

Govinda Sai
Updated on 19-Jun-2020 11:23:44

2K+ Views

To call a function on click of a button in JavaScript, use onclick. Try to run the following code to call a function onclick in JavaScript −Example                    function sayHello() {             document.write ("Hello there!");          }                     Click the following button to call the function                             Use different text in write method and then try...    

What are Complex Data types in JavaScript?

Shubham Vora
Updated on 15-Nov-2022 10:46:59

2K+ Views

In this tutorial, we will learn complex data types in JavaScript. JavaScript has multiple built-in data types to store data in different formats. The data types of JavaScript can be divided into two groups, and those are primitive data types and non-primitive data types. Number, String, Boolean, Undefined and Null are part of the primitive data type, whereas the Array and Object are part of the non-primitive data type. The typeof operator is used to identify the data types. The primitive data types are simple and easy to use. In contrast, the non-primitive data types (Array and Object) are relatively ... Read More

How to create Empty Values String in JavaScript?

seetha
Updated on 19-Jun-2020 11:20:59

3K+ Views

To create empty values string in JavaScript, you can try to run the following code −Example                    var val;          val = "";          document.write("Value: "+val);          document.write("Type: "+typeof val);                  

Advertisements