18

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?

5
  • 3
    Possible duplicate of JavaScript: How do I print a message to the error console? Commented Jan 12, 2016 at 0:21
  • 2
    That does look very like Resig stuff. Are you from Khanacademy? Methods like fill & textSize are not native in javascript. It's a part of a library. Commented Jan 12, 2016 at 0:23
  • ok guys, i get it, problem is there is no question here that shows me how i actually USE the javascript!= function. EX: Where do I put it? Do I put Javascript != { and then code? or....what? I've never used it so, maybe i'm nuking it, but i'm trying to use it and It's not working.....neither it nor the console.log is not working because i have no idea how to use those things. Commented Jan 12, 2016 at 0:49
  • It probably shouldn't be tagged with NetBeans. The screenshot shows a file with file extensions ".js" (JavaScript). Perhaps NetBeans is just the IDE or text editor that is used for the JavaScript file? Mentioning NetBeans at all may cause unnecessary confusion. But the OP has left the building: "Last seen more than 1 year ago" Commented Sep 25, 2022 at 13:05
  • From the NetBeans article: "The NetBeans JavaScript editor provides extended support for JavaScript, Ajax, and CSS.". So NetBeans may no longer imply Java (though it may still be the default association). Commented Sep 25, 2022 at 13:13

3 Answers 3

36

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."); 
Sign up to request clarification or add additional context in comments.

1 Comment

"confusing JavaScript with Java" probably refers to the mentioned "System.out.println" function being a Java function.
14

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) 

Comments

1

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

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

2 Comments

Is there a name for this technique? Why is it necessary to create an alias?
print is more or less familiar :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.