Functions & Procedures in JavaScript (OCR A-Level Computer Science): Revision Notes
📚 Revision Notes
Functions & Procedures in JavaScript
Overview
Functions and procedures in JavaScript encapsulate reusable code. Functions can accept inputs, process them, and return outputs, while procedures simply execute code.
Key Concepts
- Defining Functions: function myFunction() { }
- Parameters and Return Values: Functions can take parameters and return results.
lightbulbExample
Example:
function add(a, b) {
return a + b;
}
console.log(add(5, 3)); // Outputs 8
Common Mistakes
- Not using return in functions: Functions without return will return undefined.
infoNote
Key Takeaways
- Functions are central to code reusability in JavaScript.
- Learn to define, call, and return values from functions.