1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
---
title: Console.log()
slug: Web/API/Console/log
tags:
- API
- Debugging
- NeedsBrowserCompatibility
- Web Entwicklung
- Web Konsole
- console
- console.dir
- console.log
translation_of: Web/API/Console/log
---
<div>{{APIRef("Console API")}}</div>
<p>Gibt eine Nachricht auf der Web-Konsole aus.</p>
<p>{{AvailableInWorkers}}</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">console.log(<em>obj1</em> [, <em>obj2</em>, ..., <em>objN</em>]);
console.log(<em>msg</em> [, <em>subst1</em>, ..., <em>substN</em>]);
</pre>
<h2 id="Parameter">Parameter</h2>
<dl>
<dt><code>obj1</code> ... <code>objN</code></dt>
<dd>Eine Liste von auszugebenden JavaScript-Objekten. Die Zeichenfolgedarstellungen der Objekte werden in der angegebenen Reihenfolge aneinandergehängt und ausgegeben.</dd>
<dt><code>msg</code></dt>
<dd>Eine JavaScript-Zeichenfolge, die Null oder mehr Ersatzzeichefolgen enthält.</dd>
<dt><code>subst1</code> ... <code>substN</code></dt>
<dd>JavaScript-Objekte durch die die Ersatzzeichenfolgen in <code>msg</code> ersetzt werden sollen. Dies gibt Ihnen zusätzliche Kontrolle über die Formatierung der Ausgabe.</dd>
</dl>
<p>Weitere Details finden Sie im Abschnitt <a href="https://developer.mozilla.org/de/docs/Web/API/Console#Outputting_text_to_the_console">Outputting text to the console</a> in der Dokumentation zu {{domxref("console")}}.</p>
<h2 id="Spezifikationen">Spezifikationen</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Spezifikation</th>
<th scope="col">Status</th>
<th scope="col">Kommentar</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("Console API", "#log", "console.log()")}}</td>
<td>{{Spec2("Console API")}}</td>
<td>Erste Definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_Kompatibilität">Browser Kompatibilität</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Grundlegende Unterstützung</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("2.0")}}</td>
<td>8</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td>Ersatzzeichenfolgen</td>
<td>{{CompatVersionUnknown}}<br>
{{CompatChrome(28)}}<sup>[1]</sup></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("9.0")}}</td>
<td>10<sup>[2]</sup></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td>Verfügbar in Workers</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("38.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Edge</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Grundlegende Unterstützung</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile("2.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>Ersatzzeichenfolgen</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile("9.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>Verfügbar in Workers</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile("38.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<p>[1] Weisst man <code>%d</code> einen negativen Wert zu, wird dieser zur nächsten negative Ganzzahl abgerundet; z. B. wird -0.1 zu -1.</p>
<p>[2] <code>%c</code> wird nicht unterstützt; <code>%d</code> wird als 0 angezeigt, falls der Wert keine Nummer ist.</p>
<h2 id="Unterschied_zu_console.dir()">Unterschied zu console.dir()</h2>
<p>In Firefox generieren beide Kommandos dieselbe Ausgabe, wenn als Parameter ein DOM-Element mitgegeben wird: Man erhält in beiden Fällen eine JSON-artige Baumstruktur.</p>
<p>In Chrome besteht aber bei gleicher Eingabe ein nützlicher Unterschied:</p>
<p><img alt="" src="https://i.imgur.com/DozDcYR.png"></p>
<p>Bemerkung:</p>
<ul>
<li><code>console.log</code> gibt das Element als HTML-artige Baumstruktur aus</li>
<li><code>console.dir</code> gibt das Element als JSON-artige Baumstruktur aus</li>
</ul>
<p>Mit <code>console.log</code> werden DOM-Elemente also speziell behandelt. Bei <code>console.dir</code> ist dies nicht der Fall. Dies ist oft dann nützlich, wenn man die vollständige Darstellung des DOM-JS-Objekts ansehen möchte.</p>
<p>Mehr Informationen dazu finden Sie unter <a href="https://developers.google.com/chrome-developer-tools/docs/console-api#consoledirobject">Chrome Console API reference</a>.</p>
<h2 id="Siehe_auch">Siehe auch</h2>
<ul>
<li><a class="external" href="http://www.opera.com/dragonfly/documentation/console/">Opera Dragonfly documentation: Console</a></li>
<li><a class="external" href="http://msdn.microsoft.com/library/gg589530">MSDN: Using the F12 Tools Console to View Errors and Status</a></li>
<li><a href="http://getfirebug.com/wiki/index.php/Console_API">Firebug wiki: Console API</a> - FireBug unterstützt noch weitere Features in seiner console.log()-Implementation, wie z. B. <a href="http://www.softwareishard.com/blog/firebug/firebug-tip-styled-logging/">styled logging</a>.</li>
<li><a href="http://nodejs.org/docs/latest/api/console.html#console_console_log_data">NodeJS: Console API</a></li>
</ul>
|