Reputation: 285
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?
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
Reputation: 31
A not-so-good solution is a simple link. Print with console.log:
let print = console.log
print('Hello, World!')
Upvotes: 1
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
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