0
<!DOCTYPE html>
<html>

<body>
  <script>
    'use strict';
    if (!String.prototype.repeat) { 
      String.prototype.repeat = function(n) {
        return new Array(n + 1).join(this);
      };
    }

    alert( "La".repeat(3) ); // LaLaLa
  </script>
</body>

</html>

I didn't understand the following line of code:

if (!String.prototype.repeat)

Dinh Dinh
  • 1
  • 1
  • 3
  • 1
    It's Javascript. You should research Javascript boolean operators and if statements. –  Dec 08 '17 at 18:31
  • Yes, the `!` in this if statement is saying if not. Please see the accepted answer [here](https://stackoverflow.com/questions/19491491/what-does-an-exclamation-mark-before-a-variable-mean-in-javascript) – Matthew Dec 08 '17 at 18:41

1 Answers1

0

This is a relational operator meaning NOT. In your example, it will return true if String.prototype.repeat does NOT exist.

D.N.
  • 2,160
  • 18
  • 26