let
are only available inside the block where they’re defined and variables declared by var
are available throughout the function in which they’re declared.never
type is assignable to every type; however, no type is assignable to never
(except never
itself).obj[0]
is always the same as obj["0"]
.Passing null to this function will throw an error
function liveDangerously(x?: number | null) {
// No error
console.log(x!.toFixed());
}
liveDangerously(1)