Prints a message to the web browser's console.
The console object is helpful for printing messages while debugging. For example, it's common to add a console.log()
statement while studying how a section of code works:
if (isPlaying === true) {
// Add a console.log() statement to make sure this block of code runs.
console.log('Got here!');
// Game logic.
}
console.error()
is helpful for tracking errors because it prints formatted messages. For example, it's common to encounter errors when loading media assets:
// Logs an error message with special formatting.
function handleFailure(error) {
console.error('Oops!', error);
}
// Try to load an image and call handleError() if it fails.
loadImage('https://example.com/cat.jpg', handleImage, handleError);
Examples
Notice any errors or typos? Please let us know. Please feel free to edit src/core/reference.js and open a pull request!
Related References
stringify
From the MDN entry: The JSON.stringify() method converts a JavaScript object or value to a JSON string.
log
Prints a message to your browser's web console.
===
The strict equality operator === checks to see if two values are equal and of the same type.
Array
A list that keeps several pieces of data in order.