Programming principles and design · Lesson 28 of 60 · Concept lesson · Optional
Abstraction
Abstraction means hiding the details and showing only what you need to use something.
You press a button on a microwave without knowing how it heats food, and a function works the same way.
Good abstractions let you think about what a piece of code does, not how it does it.
Picture it
Code example
function average(numbers) {
let total = 0;
for (const n of numbers) total += n;
return total / numbers.length;
}
console.log(average([2, 4, 6]));Output: 4
You use average without caring how it adds and divides.
def average(numbers):
total = 0
for n in numbers:
total += n
return total / len(numbers)
print(average([2, 4, 6]))Output: 4.0
You use average without caring how it adds and divides.
Check yourself
Pick an answer for each question. You can retry as many times as you like.
Loading the questions…