Javascript 如何使用javascript打印到控制台?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34733505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to print to console using javascript?
提问by Sloan Brown
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?
学习JS
,第一次使用。netbeans
我的代码可以编译,但我不知道如何打印到控制台屏幕。我试过这个system.out.println
功能,但还是不行。我究竟做错了什么?
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?
编辑:这个问题是不同的,因为我以前从未真正见过使用过这些函数。在我在线使用的所有其他程序中,输出是自动的,因此要添加“console.log(....文本?
回答by uniqueusername
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.
看起来您将 Javascript 与 Java 混淆了。他们不是同一种语言。NetBeans 是 Java 的开发环境,而不是 Javascript。但是要回答您的主要问题,要在 JavaScript 中打印到控制台,您可以像这样使用 console.log() 函数。
console.log(text);
In your case, you could write
在你的情况下,你可以写
console.log("Obama is " + obama.age + " years old.");
回答by Manikandan C
Use console.log("some text")
to print the text
使用console.log("some text")
打印文本
(or)
(或者)
If you want to print the value stored in the variable then you can give the variable name inside the console.log()
如果要打印存储在变量中的值,则可以在 console.log()
e.g.
例如
var text = "some text"
console.log(text)