assert method

Sends a message to the console if the expression provided evaluates to false. The message text color is red and it is prefaced by an error icon.

Internet Explorer 10



Console.assert(test, message, optionalParams);


test [in]

Type: boolean

An expression that if false, will cause an assert message to be sent. True results, no message is sent.

message [in]

Type: DOMString

The message to display.

optionalParams [in]

Type: any

A value or string that can be used with replaceable parameters in the main message.

Return value

This method does not return a value.


The optional parameters can be used to provide a replaceable value in the message. For example, you could include a specific message or value as the optional parameter, rather than building a string by concatenating the value to the message string.

  function sendAssertConsole(cmpValue) {
        window.console.assert( (cmpValue > 3), "%s is too small", cmpValue);

See also