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);
示例
Notice any errors or typos? Please let us know. Please feel free to edit src/core/reference.js and open a pull request!