Found 10878 Articles for Web Development

How to delete a getter using the delete operator in JavaScript?

Prince Varshney
Updated on 06-Dec-2022 09:30:06

623 Views

In this tutorial, we are going to learn how we can delete a getter function using the delete operator in JavaScript. Getter functions are used to get the property of an object and bind the property with the getter function i.e., whenever the property is called the getter function will also be called with it. You can only have one getter or setter per name on an object as we cannot create more than two getters using the same name in JavaScript. To delete a getter function in JavaScript we use the delete operator which uses the keyword “delete”. Syntax ... Read More

How to define getter and setter functions in JavaScript?

Ayyan
Updated on 16-Jun-2020 08:11:42

175 Views

GetterWhen a property is accessed, the value gets through calling a function implicitly. The get keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.SetterWhen a property is set, it implicitly call a function and the value is passed as an argument. With that the return value is set to the property itself. The set keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.ExampleHere’s an example showing how to implement both getter and setterLive Demo                   ... Read More

How to set a default parameter value for a JavaScript function?

Prabhdeep Singh
Updated on 07-Nov-2022 08:29:45

372 Views

In this tutorial, we are going to learn to set a default parameter value for a JavaScript function. JavaScript is an object-oriented programming language that provides us the facility to perform both functional and class-oriented programming which gives us the facility to manage code easily and can re-use the code as well. In functional programming, the programmer creates a function that may take some parameters and may return some value after performing a number of steps it was supposed to do. The value of parameters for the function can be a string, number, object, etc. and we can also set ... Read More

What is the use of return statement inside a function in JavaScript?

Alankritha Ammu
Updated on 07-Jan-2020 08:51:24

217 Views

The “return” statement in JavaScript mentions a value, which you like to return. Inside a function, the value is returned to the function caller.ExampleYou can try to run the following code to implement return statement inside a functionLive Demo                    function multiply(num1, num2) {             return num1 * num2;          }          var result = multiply(5, 10);          document.write("Multiplication: "+result);          

What are the latest operators added to JavaScript?

Ayyan
Updated on 16-Jun-2020 08:10:14

56 Views

The latest operators added to JavaScript are spread operator and rest.Rest operatorWith rest parameter, you can represent number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and preceds a parameter.ExampleLet’s see the following code snippet to define rest parameter                    function addition(…numbers) {             var res = 0;             numbers.forEach(function (number) {                res += number;   ... Read More

Usage of rest parameter and spread operator in JavaScript?

Anjana
Updated on 16-Jun-2020 08:08:19

217 Views

Rest ParameterWith rest parameter, you can represent a number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and precedes a parameter.Let’s see the following code snippet to define rest parameter −                    function addition(…numbers) {             var res = 0;             numbers.forEach(function (number) {                res += number;             });     ... Read More

How to use Spread Syntax with arguments in JavaScript functions?

Abhishek Kumar
Updated on 10-Nov-2022 08:28:14

1K+ Views

We use the Spread Syntax of JavaScript to expand an array, string, or object in place. Such types of values are called iterable. This is similar to destructuring the iterable in place. Its utility in a function call allows us to extract function parameters from an iterable. In this tutorial, we learn how to use Spread Syntax with arguments in JavaScript functions. Spread operator in JavaScript A Spread operator, denoted with (...) followed by the name of the iterable expands the iterable into its constituent elements. e.g. const [x, y, ...z] = [1, 2, 3, 4, 5] This creates ... Read More

What is the difference between rest parameters and the arguments object in Javascript?

Manikanth Mani
Updated on 16-Jun-2020 08:03:52

576 Views

Rest parametersWith rest parameter, you can represent a number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and precedes a parameter.Arguments objectArguments object in JavaScript is an object, which represents the arguments to the function executing.Here is the difference between rest parameters and the arguments object.Arguments object includes all arguments passed to the function, whereas rest parameters are those, which are not given another name.The rest parameters are Array instances, whereas arguments object isn’t an array. Array instances are the following methods: ... Read More

What are async methods in JavaScript?

varun
Updated on 15-Jun-2020 13:18:08

101 Views

The async function declaration as the name suggests defines an asynchronous function. This function returns an AsyncFunction object.SyntaxHere’s the syntax −async function functionname([param[, param[, ... param]]]) {    statements to be executed }ExampleLet’ see an example, which prints the result after 5 seconds −                    function displayFunction(num) {             return new Promise(resolve => {                setTimeout(() => {                   resolve(num);                }, 5000);             });          }          async function add2(num) {             const x = displayFunction(7);             const y = displayFunction(5);             return num * await x * await y;          }          add2(15).then(result => {             document.write("Multiplication Result (after 5 seconds): "+result);          });          

What are generator functions in JavaScript?

Prabhas
Updated on 16-Jun-2020 06:27:28

176 Views

Generator Functions allows execution of code in between when a function is exited and resumed later. So, generators can be used to manage flow control in a code. Cancel asynchronous operations easily since execution can be paused anytime.Here’s the syntax; do not forget to add an asterisk after the “function” keyword. You can add an asterisk using any of the following −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}ExampleLet’s see how to use a generator functionLive Demo                    function* display() {             ... Read More

Advertisements