- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6685 Articles for Javascript
![Ayyan](https://www.tutorialspoint.com/assets/profiles/13521/profile/60_79767-1512650417.jpg)
194 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
![Prabhdeep Singh](https://www.tutorialspoint.com/assets/profiles/546958/profile/60_1428686-1667456005.jpg)
397 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
![Alankritha Ammu](https://www.tutorialspoint.com/assets/profiles/13523/profile/60_83090-1512649277.jpg)
223 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);
![Ayyan](https://www.tutorialspoint.com/assets/profiles/13521/profile/60_79767-1512650417.jpg)
62 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
![Anjana](https://www.tutorialspoint.com/assets/profiles/13774/profile/60_78029-1512648681.jpg)
236 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
![Abhishek Kumar](https://www.tutorialspoint.com/assets/profiles/522605/profile/60_2286409-1663737781.jpeg)
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
![Manikanth Mani](https://www.tutorialspoint.com/assets/profiles/13524/profile/60_53242-1512705034.jpg)
609 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
![varun](https://www.tutorialspoint.com/assets/profiles/13559/profile/60_29674-1512637943.jpg)
117 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); });
![Prabhas](https://www.tutorialspoint.com/assets/profiles/13554/profile/60_90506-1512543588.jpg)
192 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
![seetha](https://www.tutorialspoint.com/assets/profiles/13549/profile/60_42938-1512640859.jpg)
387 Views
A method in JavaScript is the action performed on objects. A JavaScript method has a function definition, which is stored as a property value. ExampleLet’s see an example to define a method in JavaScriptLive Demo var department = { deptName: "Marketing", deptID : 101, deptZone : "North", details : function() { return "Department Details" + "Name: " + this.deptName + " Zone: " + this.deptZone + "ID: " + this.deptID; } }; document.getElementById("myDept").innerHTML = department.details();