JavaScript console.log()

This is a preview lesson
Register or sign in to take this lesson.

JavaScript console.log() is a function that displays any kind of variables that have been defined before in it or any other message to the debugger’s console. The console.log() is commonly used for testing purposes during the development phase.

Syntax

console.log(message)

Parameters: An array, an object, or any other message can be passed as a parameter.

Return Value: It returns the value of the parameter given.

Example

  • Log a sentence
console.log("This will print the message.");

The output for the above code will be : This will print the message.

  • Log a value stored in a variable
const GREET = "Hello" ;
const NAME = "User" ;

console.log(GREET + '  ' + NAME);

The output of the above code will be Hello User .

  • Log a value stored in a variable with a static value
const GREET = "Hello" ;

console.log(GREET + '  User');

The output of the above code will be Hello User. Same as the second example but the difference is the second example uses the variable whereas the third example uses the variable and static value.

Conclusion

In this lesson, you learn about the JavaScript console log function.