JS Coding Questions Logo
JS Coding Questions
#260💼 Interview💻 Code

What happens If I pass string type for getPrototype method

Advertisement

728x90

In ES5, it will throw a TypeError exception if the obj parameter isn't an object. Whereas in ES2015, the parameter will be coerced to an Object.

javascript
1// ES5
2
3Object.getPrototypeOf("James"); // TypeError: "James" is not an object
4// ES2015
5
6Object.getPrototypeOf("James"); // String.prototype

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 3

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
260of476
What happens If I pass string type for getPrototype method | JSCodingQuestions.com