← All lectures

Lecture 16 · 35 min

Functions — Introduction

Breaking programs into reusable building blocks: defining functions, calling them, parameters, return values, and prototypes.

Why functionsDefinition & callParameters & returnPrototypesCall stack
Slide 1 / 15

Why use functions?

A function is a named block of statements that does one specific job. Instead of writing the same code multiple times, you write it once as a function and call (use) it wherever you need it.

Benefits:

  • Reusability — write once, use many times
  • Readability — calculateArea(5) is clearer than 10 lines of math
  • Easier debugging — fix a bug in one place, fixed everywhere
  • Teamwork — different people can write different functions
← / → navigateF fullscreenEsc exit⌘K search