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);
Ejemplos
This page is generated from the comments in src/core/reference.js . Please feel free to edit it and submit a pull request!
Referencias Relacionadas
Array
Una lista que mantiene diferentes tipos de datos en orden Los arreglos son útiles para almacenar datos relacionados.
class
Una plantilla para crear objetos de un tipo en particular.
for
Una forma de repetir un bloque de código cuando se conoce el número de iteraciones.
function
Un grupo de declaraciones con nombre.