JavaScript Code


How to print string to console output in JavaScript?


Print string to console

Given a string, print the string to console output, using JavaScript.

Solution

To print given string str to console output in JavaScript, call console.log() method and pass the string str as argument to the method.

console.log(str);

Programs

1. Given a string str. Print the string to console output.

var str = 'hello world';
console.log(str);