Skip to the workspace
Pebellslearn by building
Functions  ›  Lesson

Built-in Functions

Built-in Functions 12 min

javascript / Built-in Functions

Explore each scene at your own pace.

01 · Built-in Functions

Built-in Functions

Built-in Functions

Built-in functions and methods are reusable operations supplied by the language or its environment. Each has a contract for inputs, outputs and side effects.

Choose an operation because you understand its behavior, not because its name sounds close.

See the mechanism

Walk through the modelBuilt-in FunctionsAuthored snapshots of the example; use Run below to test the code.
title" Quiet mornings "
The original text includes leading and trailing spaces.
1 of 3

Follow one example

javascript

trim returns a new string; it does not mutate the original title. Reading title.length still includes the surrounding spaces. Math.ceil rounds upward, so 3.2 becomes 4. console.log is an environment-provided output facility. Consult the contract before assuming any method mutates its input or has the same rounding behavior as another.

Predict, change and check

Predict: Would title.trim() alone permanently remove spaces from title?

Test your explanation: Print title surrounded by brackets before and after trim. Store the returned string to keep the cleaned result.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Know the global function's conversion policy

Built-in global functions such as parseInt, parseFloat and Number conversion helpers have different contracts. Parsing a numeric prefix is different from validating an entire numeric field. Number.isNaN does not coerce its input, while the global isNaN does.

encodeURIComponent is useful for a single URI component, not as a universal encoder for every assembled URL. Use URL and URLSearchParams for a browser URL boundary when appropriate. Avoid eval as a way to parse user-supplied data: JSON.parse is a data parser, and even its successful result still needs application validation.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.