JavaScript: Functions Flashcards
What are functions?
Functions are reusable blocks of code that perform a specific task.
What is a function declaration?
What is the syntax?
function declareHello() {
console.log(“Hello, I am a function declaration.”);
console.log(“———————————–”);
return;
What is a function expression?
What is the syntax?
const expressHello = function () {
console.log(“Hello, I am a function expression.”);
console.log(“———————————–”);
return;
};
How do you execute a function?
What is the syntax?
Functions must be called to execute
Example:
// Function
function declareHello() {
console.log(“Hello, I am a function declaration.”);
console.log(“———————————–”);
return;
//Function call
declareHello();
What are function parameters?
Parameters give a name to the data to be passed into the function.
What is the syntax for function parameters?
What are function arguments?
function declareHelloAgain(x, y, z, d, f) {
console.log(
Hello, the values of my parameters are ${x}, ${y}, ${z}, ${d}, ${f}.
);
console.log(“———————————–”);
return;
// Function arguments give parameters their values
// Here the parameter x is given the value 7 when the function is called
declareHelloAgain(7, “Hello”, true, dog
, cat
);