Skip to main content

Lambda Functions

C

// TODO

Back to top

C++ (Cpp)

// TODO

Back to top

C# (Csharp)

// TODO

Back to top

Java

// TODO

Back to top

Rust

// TODO

Back to top

Go

// TODO

Back to top

Javascript

// Also Known as Arrow Functions

// ------------------------------------
// Definition
// ------------------------------------

const functionName = ( [parameters] ) => {
// ...
}

// ------------------------------------
// Declaration Example
// ------------------------------------

const functionName = (x, y) => { /*...*/ } // Default
const functionName = (x, y) => { return x * y; }
const functionName = (x, y) => x * y; // Same as above. (Return and {} can be omitted for simple/small code)
const functionName = (x) => { /*...*/ } // one parameter
const functionName = x => { /*...*/ } // one parameter (the parentheses can be omitted)
const functionName = () => { /*...*/ } // no parameter


// ------------------------------------
// Named Parameters (Keyword Arguments)
// ------------------------------------

// TODO


// ------------------------------------
// Optional Parameters
// ------------------------------------

// TODO


// ------------------------------------
// Default Argument for Parameters
// ------------------------------------

// TODO


// ------------------------------------
// Variable Number of Arguments to a Function Parameters
// ------------------------------------

// Option 1 - rest parameters syntax (Also Known as Spread Operator)
const addAll = (...args) => {
let result = 0;

for (element of args) {
result += element
}

return result
}

console.log(addAll(1, 2, 3))

// Option 2 - Arguments Object
// "Arguments Object" does NOT work with Arrow Functions

More Info:

Back to top

Typescript

// TODO

Back to top

Python

# TODO

Back to top