The "use strict" Directive

Strict mode makes it easier to write "secure" JavaScript. Strict mode changes previously accepted "bad syntax" into real errors. In normal JavaScript, a developer will not receive any error feedback assigning values to non-writable properties.

An example in normal JavaScript.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <script>
      var result;
        function getText() {
          var someText = prompt("Give me something to capitalize");
          capWords(someText);
          alert(result.join(" "));
        };
        function capWords(input) {
          var counter;
          var inputArray = input.split(" ");
          var transformed = "";
          result = [];
          for (counter = 0; counter < inputArray.length; counter++) {
            transformed = [
              inputArray[counter].charAt(0).toUpperCase(),
              inputArray[counter].substring(1)
            ].join("");
            result.push(transformed);
          }
        };
        document.getElementById("main_button").onclick = getText;
    </script>
  </head>
  <body>
    <button id="main_button" type="button">Click Me!</button>
  </body>
</html>

Start Thinking Functionally - "use strict" Directive

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <script>
      (function() {
        "use strict";
        var capify = function(str) {
          return [str.charAt(0).toUpperCase(), str.substring(1)].join("");
        };
        var processWords = function(fn, str) {
          return str.split(" ").map(fn).join(" ");
        };
        document.getElementById("main_button").addEventListener("click", function(e) {
          var something = prompt("Give me something to capitalize");
          alert(processWords(capify, something));
        });
      }());
    </script>
  </head>
  <body>
    <button id="main_button" type="button">Click Me (2)!</button>
  </body>
</html>