Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print to console using javascript?

learning JS, 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

EDIT: This question is different because i've never actually seen these functions used before. 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?

like image 661
Sloan Brown Avatar asked Jan 12 '16 00:01

Sloan Brown


People also ask

How do you print to console in JavaScript?

warn(), console. error() and console.info() methods are utilized to print to the console in JavaScript. The console. log() method is the most adapted method to display strings, arrays, and object properties to the console.

How do I print a value in console?

The console. log() is a function in JavaScript that is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.

How do you print a console in HTML?

html on the browser (e.g. chrome), right-click on the browser and click inspect. Click console from inspecting tab, you will see console print out of "Hello Javascript").

Can JavaScript read the console?

What's in the console can't be read from JavaScript. console. logs contains all what was logged. You can clean it at any time by doing console.


2 Answers

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.");
like image 68
uniqueusername Avatar answered Oct 12 '22 05:10

uniqueusername


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)
like image 34
Manikandan C Avatar answered Oct 12 '22 05:10

Manikandan C