Sloan Brown
Sloan Brown

Reputation: 285

How can I print to the console using JavaScript?

I am learning JavaScript for the first time using NetBeans. My code can compile, but I don't know how to print to the console screen. I've tried the System.out.println function, but that still doesn't work. What am I doing wrong?

Enter image description here

At all the other programs I've used online, the output was automatic, so to add "console.log()", where do I put it, and how do I make it show the values of the variables like in the text?

Upvotes: 16

Views: 213158

Answers (3)

Alex Samarkin
Alex Samarkin

Reputation: 31

A not-so-good solution is a simple link. Print with console.log:

let print = console.log
print('Hello, World!')

Upvotes: 1

uniqueusername
uniqueusername

Reputation: 550

That looks like you're confusing JavaScript with Java. They're not the same language. NetBeans is a development environment for Java, not JavaScript. But to answer your main question, to print to the console in JavaScript, you can use the function console.log() like this.

    console.log(text);

In your case, you could write

    console.log("Obama is " + obama.age + " years old.");

Upvotes: 34

Manikandan C
Manikandan C

Reputation: 698

Use console.log("some text") to print the text

(or)

If you want to print the value stored in the variable then you can give the variable name inside the console.log()

e.g.

var text = "some text"
console.log(text)

Upvotes: 14

Related Questions