From the course: TypeScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Typeof operator

Typeof operator

- [Instructor] In this video, I'm going to show you how to take advantage of a JavaScript feature that's been around for a long time, the typeof operator. If you've never used JavaScript's typeof operator, it looks like this. If I were to execute the code on lines one through four, I would see in the console, the word string and Boolean printed out because those are the types of the X and Y variables. Now, this is typical JavaScript behavior. It has nothing to do with type script. In fact, I've been writing JavaScript code like this for years. This is, once again, another example of using JavaScript's dynamic typing system to write very flexible logic. In this case, this function accepts a single parameter, named name or contact, the value of which, from what we can tell from the code, it expects to be either a string or a contact object, but here's the problem. We can understand, from looking at this code, that the…

Contents