JavaScript Function Examples
The following JavaScript section contains a wide collection of JavaScript examples. Many of these programming examples contain multiple approaches to solve the problem.
We have a complete list of Javascript Function, to check those please go through this JavaScript Function Complete Reference article.
We have created an article of JavaScript Examples, and added list of questions based on Array, Object, Function, …, etc. Please visit this JavaScript Examples to get complete questions based articles list of JavaScript.
We have created a complete JavaScript Tutorial to help both beginners and experienced professionals. Please check this JavaScript Tutorial to get the complete content from basic syntax and data types to advanced topics such as object-oriented programming and DOM manipulation.
JavaScript Function Examples
A function in JavaScript is a set of statements that perform a specific task. It takes inputs, and performs computation, and produces output. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs, we can call that function.
Syntax:
function myFun(parameter) { statements... };
Example: Here is the basic JavaScript function example in which we add 2 elements.
Javascript
function myFunction(a, b) { return a + b; } // Calling the function const result = myFunction(5, 2); console.log(result); |
7