Recap: Core Types Practice
Part of the Introduction To TypeScript section of Coddy's JavaScript journey — lesson 12 of 73.
Challenge
EasyCreate a function named getTypeInfo that takes a parameter of type any and returns a string.
The function should use the typeof operator to determine the type of the input parameter and return that type as a string.
Test your function by calling it with the following values and printing each result:
- Call
getTypeInfo("Hello") - Call
getTypeInfo(42) - Call
getTypeInfo(true) - Call
getTypeInfo(null)
Print each result on a separate line in the order listed above.
Try it yourself
// TODO: Write your code here
// Create the getTypeInfo function that takes a parameter of type any and returns a string
// Test the function with the required values and print each result
console.log(getTypeInfo("Hello"));
console.log(getTypeInfo(42));
console.log(getTypeInfo(true));
console.log(getTypeInfo(null));All lessons in Introduction To TypeScript
1Getting Started with TS
What is TypeScript?Why Use TypeScript?Your First TypeScript CodeCompilation Process & ErrorsRecap: Introduction to TS4Working with Functions
Typing Params & Return ValuesTyping Arrow FunctionsThe 'void' Return TypeOptional Parameters with '?'Default Parameter ValuesTyping Rest ParametersDefining Function TypesRecap: Building Typed Funcs2Core Types
Basic Types: str, num, booleanThe 'any' Type: Escape HatchThe 'unknown' TypeWorking with 'null' & 'undef'Type Inference in ActionExplicit Type AnnotationsRecap: Core Types Practice5Types: Aliases, Unions & Inter
Type Aliases for PrimitivesUnion Types ('|')Working with Union TypesLiteral TypesIntersection Types ('&')Combining Type AliasesRecap: Advanced Type Combos3Data Structure: Arrays & Tuple
Typed Arrays'readonly' Modifier for ArraysWhat is a Tuple?Declaring and Accessing TuplesDestructuring TuplesReadonly TuplesMulti-dimensional Typed Arrays Spread Operator with ArraysRecap: Arrays and Tuples