JavaScript console.log() Examples

console.log() is a proper JavaScript method to print data into the developer’s console.

//Syntax
console.log(x);

The parameter X can be of any data type: a string, an inter, or an object. If the x doesn’t exist, it prints out the error: Uncaught ReferenceError: x is not defined.

let name = 'John';
let age = 30;
console.log(`My name is ${name} and I am ${age} years old.`);

let name = 'John';
let age = 30;
console.log(name, age);

let numbers = [1, 2, 3, 4, 5];
console.log(numbers);

let person = { name: 'John', age: 30 };
console.log(person);
var str = "TL Dev Tech"; 
console.log(str); 

var brands = ['Honda', 'Huyndai', 'Toyota', 'BMW'];
console.log(brands); 
console.log(5+10);
console.log('He is ' + 15 + ' years old');

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close