How to Use typeof With Functions
May 6, 2021
typeof
is a useful operator that returns the primitive type of the given variable.
typeof
can be used with function-like syntax, however, it is not a function.
Be careful, you will get a syntax error if you try to use typeof
as a variable!
typeof(42); // `number`
typeof(typeof); // syntax error
You can use typeof
on functions, and it will return as
function
.
function test() {
console.log('hello world');
}
typeof test; // 'function'
More Fundamentals Tutorials
- Convert a Set to an Array in JavaScript
- What Does Setting the Length of a JavaScript Array Do?
- Get the Last Element in an Array in JavaScript
- Skip an Index in JavaScript Array map()
- Conditionally Add an Object to an Array in JavaScript
- Validate Emails using Regex in JavaScript
- JavaScript Copy to Clipboard