| Viewed 156 times

How to create a function in javascript


How to create a function in javascript

1 Answer
Mohammad Qandeel
Answered
10

The function is defined with the function keyword, followed by a function name, followed by parentheses ().

The function name follows the same rules for writing variable names

The body of the function is placed inside curly brackets: {} 

Example of writing a function in javascript

//create function 
function testFunction(s1, s2) {
  return s1 + s2;   // The function returns the concatenation of s1 and s2
}
console.log(testFunction('Qandeel','Academy'));
//call testFunction() function 
//expected output 'QandeelAcademy'