CodingNeed.

1 · Write contracts · 7 MIN

Describe a value

Variables keep values available for later instructions.

A type annotation describes the values a binding can hold. number covers JavaScript numeric values; string describes text. Types are removed before execution. This playground transpiles code and reports syntax errors; it does not perform full semantic type checking. Use tsc in a project for that.

A label on a box tells you which value you are working with. let lets you replace what is in that box.

Read the example

const points: number = 5;
console.log(points + 2);
Check the expected output
7

Your challenge

Return the input number plus 10. Accept zero and negative numbers too.

Common trap

Assigning to a const binding again throws an error. const does not freeze an object.

Next lesson: Type a function