JavaScript Lesson 3: Functions and Scope
Page 1: Introduction to Functions
What is a Function?
o A function is a block of reusable code designed to perform a specific task.
o Functions can be called when needed, making your code modular and easy to maintain.
Why Use Functions?
o Functions help break down complex problems into smaller, manageable tasks.
o Functions can be reused throughout your program, saving time and reducing code
duplication.
Basic Syntax of a Function:
Page 5: Understanding this Keyword
What is this?
o In JavaScript, this refers to the object that is executing the current function.
o The value of this depends on how the function is invoked.
o Global context: In the global scope, this refers to the global object (in browsers, it's
window).
Example: