
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What are functions in JavaScript?
A function is a group of reusable code which can be called anywhere in your program. This eliminates the need of writing the same code repeatedly. It helps programmers in writing modular codes.
Before we use a function, we need to define it. The most common way to define a function in JavaScript is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.
Syntax
The following is the syntax −
<script> function functionname(parameter-list) { statements } </script>
- Related Articles
- What are callback functions in JavaScript?
- What are generator functions in JavaScript?
- What are immediate functions in JavaScript?
- What are Partial functions in JavaScript?
- What are JavaScript Math Functions?
- What are JavaScript Nested Functions?
- What are JavaScript Factory Functions?
- What are optional arguments in JavaScript Functions?
- What are Rest parameters in JavaScript functions?
- What are Self-Invoking Anonymous Functions in JavaScript?
- What are different ways of defining functions in JavaScript?
- What are variadic functions in Java?
- What are virtual functions in C#?
- Regular functions vs Arrow functions in JavaScript?
- What are MySQL group functions?

Advertisements