

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The importance of simplifying complex buttons using user-defined functions and abstraction in javascript. It explains how functions reduce code length and complexity, and provides examples of defining and using simple user-defined functions. Additionally, it introduces the concept of abstraction and how it helps us focus on the big picture by ignoring unimportant details.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Math.random Math.floor
e.g., a single call to Math.sqrt replaces the underlying complex algorithm
the code from the button is moved to the user-defined Greet function as a result, the button is greatly simplified
GENERAL RULE: if more than one statement is to be associated with a button, define a separate function
in modern life, we are constantly confronted with complexity we don't necessarily know how it works, but we know how to use it e.g., how does a TV work? a car? a computer?
to use a TV/car/computer, it's not important to understand the inner workings we ignore unimportant details and focus on those features relevant to using it e.g., TV has power switch, volume control, channel changer, …
parameters local variables return statements
parameters appear in the parentheses, separated by commas
if require some temporary storage in performing calculations, then declare local variables using the keyword var, separated by commas a local variable exists only while the function executes, so no potential conflicts with other functions
consists of the keyword return followed by a variable or expression