Trusted answers to developer questions

Javascript functions

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

Functions are a kind of subroutine that performs a specific task. Like every other programming language, JavaScript has its own rules for declaring functions. Some syntax may seem familiar; however, there are a few things to notice.

Syntax

The function keyword is placed before the name of the new function to indicate that a new function is being declared. Curly braces {} are used to indicate the function’s body, like most other languages.

function HelloWorld(args){
    // your code
}
Parts of a function
Parts of a function

Code

Console

Anonymous function

In JavaScript, we can make functions without a name called anonymous functions. In the example below, the variable HelloWorld can lose the function declaration and be replaced by any other value.

Console

Lambda Functions

Lambda functions are similar to anonymous functions, but they have more flexible features and syntax. An arrow function is another of this type of function.

var functionName = (parameters) => // function body
Console

RELATED TAGS

basics
functions
javascript
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?