JavaScript(JS) JS write to console

ww‮ditfigi.w‬ea.com

In JavaScript, you can write to the console using the console.log() method. Here's an example:

console.log('Hello, world!');

In the above example, we call the console.log() method with a string argument 'Hello, world!'. When the code is executed, the string will be printed to the console.

You can also pass multiple arguments to the console.log() method, which will be printed to the console separated by spaces. For example:

const name = 'John';
const age = 30;
console.log('My name is', name, 'and I am', age, 'years old.');

In the above example, we declare two variables name and age. We then call the console.log() method with multiple arguments, which will be printed to the console separated by spaces. When the code is executed, the following string will be printed to the console:

My name is John and I am 30 years old.

In addition to console.log(), the console object also provides other methods for writing to the console, such as console.error(), console.warn(), and console.info(). These methods are used to print error messages, warning messages, and informational messages, respectively.