0% found this document useful (0 votes)
2 views

javascriptlesson3

This lesson introduces functions in JavaScript, explaining their purpose as reusable code blocks that simplify complex tasks and enhance code maintainability. It emphasizes the importance of functions in reducing code duplication and provides an overview of the basic syntax. Additionally, it covers the 'this' keyword, detailing its context-dependent value during function execution.

Uploaded by

vanguyen103
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

javascriptlesson3

This lesson introduces functions in JavaScript, explaining their purpose as reusable code blocks that simplify complex tasks and enhance code maintainability. It emphasizes the importance of functions in reducing code duplication and provides an overview of the basic syntax. Additionally, it covers the 'this' keyword, detailing its context-dependent value during function execution.

Uploaded by

vanguyen103
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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:

You might also like