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?
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?
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.
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.
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").
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.
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.");
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With