Junior
Millised on kaks viisi funktsioonide deklareerimiseks JavaScriptis?
sobes.tech AI
Vastus AI-lt
There are two main ways to declare functions:
-
Function Declaration:
// Function declaration with the name 'sum' function sum(a, b) { return a + b; } -
Function Expression:
// Function expression assigned to the variable 'subtract' const subtract = function(a, b) { return a - b; };
There is also a variant of the function expression - Arrow Function:
// Arrow function assigned to the variable 'multiply'
const multiply = (a, b) => a * b;