Javascript, Built-In Methods

I’m on the second part where you have to find a string that trims whitespace. I found String.prototype.trim() . I put it in the code as console.log(’ Remove whitespace '.String.prototype.trim()); . It came as a type error, saying that ‘prototype’ is undefined, but the instructions say that it is correct. Who do I believe?

Pretty sure this doesn’t come up in “Getting Started”, but what the hey?

Your opening string is the object to replace String.prototype.

’    Remove whitespace   '

is a string primitive that as recognized gets a String object wrapper. Given this wrapper, it now inherits from the prototype of that parent object. String is the parent class of string objects, and its prototype gives us the trim method.

 ’    Remove whitespace   '.trim()

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.