Practice Check if Object Instance of Class
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#2618
LeetCode ProblemCheck if Object Instance of Class
Problem Statement
Write a function that checks if a given value is an instance of a given class or superclass. For this problem, an object is considered an instance of a given class if that object has access to that class's methods. There are no constraints on the data types that can be passed to the function. For example, the value or the class could be undefined.
Source: Check if Object Instance of Class on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
func = () => checkIfInstanceOf(new Date(), Date)
Output
true
# Example 2
Input
func = () => { class Animal {}; class Dog extends Animal {}; return checkIfInstanceOf(new Dog(), Animal); }Output
true
# Example 3
Input
func = () => checkIfInstanceOf(Date, Date)
Output
false
# Example 4
Input
func = () => checkIfInstanceOf(5, Number)
Output
true
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.