At the second instruction, we are told to use the trim() function to remove the whitespaces from console.log(’ Remove whitespace '); leaving only ‘Remove whitespace’.
Why does .trim() not also remove the space between ‘Remove’ and ‘whitespace’?
built-in methods like .trim() are written by a developer, as such they decide the behavior of the method. For trim it was decided only to remove trailing and leading spaces
Hey, sorry if there’s already an answer to my question, but it’s still not clear to me what is main difference between JS object and instance?
Thank you
I have absolutely no idea what this is saying can anyone please help me understand this tutorial? How did i get here?
console.log(‘hello’.toUpperCase()); // Prints ‘HELLO’
console.log(‘Hey’.startsWith(‘H’)); // Prints true
Let’s look at each of the lines above:
On the first line, the .toUpperCase() method (?) is called on the string (?) instance (?) ‘hello’. The result is logged (?) to the console (?) . This method returns a string in all capital letters: ‘HELLO’.
On the second line, the .startsWith() method (?) is called on the string instance (?) ‘Hey’. This method also accepts the character ‘H’ as an input, or argument, between the parentheses. (?) (?) (?) (?) (?) Since the string ‘Hey’ does start with the letter ‘H’, the method returns the boolean true. (?) (?) (?) (?) (?) (?)
Can someone please explain what this means?
In the second console.log() statement in app.js , we have a string ' Remove whitespace ' which has spaces before and after the words 'Remove whitespace' .
If we browse the JavaScript string documentation, we find several built-in string methods that each accomplish a different goal. The one method that seems ideal for us is .trim() .
Use the method to remove the whitespace at the beginning and end of the string in the second console.log() statement.
The method is akin to a function, but it is not freestanding. It is inherited from the constructor prototype for String objects and can only be called on that data type.
I’m trying to use the trimStart() method from JS documentation but I keep getting an error. Please let me know whether I am doing something incorrectly or this is a bug. Thanks!
console.log(’ Remove whitespace '.trimStart());
/home/ccuser/workspace/introduction-to-javascript-built-in-methods/app.js:1
(function (exports, require, module, __filename, __dirname) { console.log(' Remove whitespace '.trimStart());
^
TypeError: " Remove whitespace ".trimStart is not a function
at Object.<anonymous> (/home/ccuser/workspace/introduction-to-javascript-built-in-methods/app.js:1:102)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3
Try using the .trim() method as suggested. It might be the case that the version of Node.js behind the LE is older than Version 10.0 which is the first version to support .trimStart().