0 of 5 problems solved0%
1 of 5

Explicit vs Inferred

In JavaScript, variables can hold values of many different types.
TypeScript lets us describe exactly what kind of values a variable can hold.

You can give a variable an explicit type with :number, or you can let TypeScript infer the type automatically from its initial value.

Example:

let score: number; // explicit number type annotation
let score = 100; // inferred number type

Your Task

  1. Give the variable greeting the type of string.

    • Give it the type annotation :string.
    • Assign it the value "Hello World".
    • Log it to the console.
  2. Now declare another variable firstName without a type annotation.

    • Assign it your own name as a string.
    • Hover over firstName in the editor to see how TypeScript inferred the type string.