I am learning javascript. I just want to understand why the strip2 () function in the code below does not work and returns an error.
<script type="text/javascript"> function strip1(str) { return str.replace(/^\s+|\s+$/g, "") }; function strip2() { return this.replace(/^\s+|\s+$/g, "") }; var text = ' Hello '; console.log(strip1(text)); </script>
Thanks.
source share