Why .padStart() and .padEnd() gives error?

I’m reading some built-in methods related to string. I learnt about .padEnd() and .padStart() method, while implementing these methods, I got errors as “str.padStart() is not a function
at Object”.

I read it here. => https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

even copy-pasting the same code from MDN throws an error. HELP
I have not yet installed Node JS on my computer so I always test my code on code-cad editor.

Codecademy is not ideal environment to test your code, given each exercise contains lesson validation.

there are plenty of good alternatives to run your JS code:
codepen.io
jsbin.com
jsfiddle.net

and many more. I would recommend using those websites instead.

running your code on jsbin:

https://jsbin.com/faqucuviqe/edit?js,console

goes absolutely fine

also, nodeJS is not the same as the JS engine within a browser. Just so you know :wink:

2 Likes

Thanks, it is working now.