Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node.js

What is console.log() in Javascript?

Educative Answers Team

The console.log() method is used to write a message to the console. It can be used to write:

  • JavaScript object(s)

  • A JavaScript string with or without substitution strings

  • Primitive values such as integers and floats

Syntax

The syntax for console.log() is shown below:

svg viewer

Code

1. Writing a string to the console

console.log('Hello from Educative!');

2. Writing an array to the console

var even = [2, 4, 6, 8, 10]
console.log(even);

3. Writing an object to the console

var student ={name: "Alice Green", age: 22, gpa: 3.7};
console.log(student);
console.log(student.name + " likes to draw in her free time.")

RELATED TAGS

node.js
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring