Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - Strict

The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables or write loose code. Strict mode changes previously accepted "bad syntax" into real errors. You can declare it globally or within the scope of a function.

Strict Mode requires you to declare variables....even if within a loop.

  • Open Developer Console
  • Click button...see error


"use strict";
function RunTest()
{
//let output = "";
let demo1 = document.getElementById("demo1");
for (let i = 0; i < 5; i++)
{
output +=`The number is ${i}<br />`;
}
demo1.innerHTML = output;
}