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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
---
title: Typy oraz struktury danych w JavaScript
slug: Web/JavaScript/typy_oraz_struktury_danych
tags:
- JavaScript
- Początkujący
- Typy danych
translation_of: Web/JavaScript/Data_structures
---
<div>{{jsSidebar("More")}}</div>
<div>Wszystkie języki programowania posiadają wbudowane struktury danych, mogą one jednak różnic się między poszczególnymi językami. Poniższy artykuł jest próbą stworzenia listy wbudowanych typów oraz struktur danych w JavaScript oraz ich właściwości. Mogą być one użyte do tworzenia innych struktur danych. Tam gdzie jest to możliwe dokonano porównania z innymi językami programowania.</div>
<h2 id="Dynamiczne_typowanie">Dynamiczne typowanie</h2>
<p>JavaScript jest językiem typowanym dynamicznie. Zmienne w Javascript nie są bezpośrednio powiązane z konkretnym typem wartości i możemy im przypisywać wartości dowolnego typu:</p>
<pre class="brush: js notranslate">let foo = 42; // foo jest teraz liczbą (number)
foo = 'bar'; // foo jest teraz ciągiem znaków (string)
foo = true; // foo jest teraz type logicznym (boolean)
</pre>
<h2 id="Data_and_Structure_types">Data and Structure types</h2>
<p>Najnowsza wersja standardu ECMAScript definiuje dziewięć typów danych:</p>
<ul>
<li>Six <strong>Data Types</strong> that are <a href="/en-US/docs/Glossary/Primitive">primitives</a>, checked by <a href="/en-US/docs/Web/JavaScript/Reference/Operators/typeof">typeof</a> operator:
<ul>
<li><a href="/en-US/docs/Glossary/Undefined">undefined</a> : <code>typeof instance === "undefined"</code></li>
<li><a href="/en-US/docs/Glossary/Boolean">Boolean</a> : <code>typeof instance === "boolean"</code></li>
<li><a href="/en-US/docs/Glossary/Number">Number</a> : <code>typeof instance === "number"</code></li>
<li><a href="/en-US/docs/Glossary/String">String</a> : <code>typeof instance === "string"</code></li>
<li><a href="/en-US/docs/Glossary/BigInt">BigInt</a><span> : </span><code>typeof instance === "bigint"</code></li>
<li><a href="/en-US/docs/Glossary/Symbol">Symbol</a><span> : </span><code>typeof instance === "symbol"</code></li>
</ul>
</li>
<li><a href="/en-US/docs/Glossary/Null">null</a><span> : </span><code>typeof instance === "object"</code>. Special <a href="/en-US/docs/Glossary/Primitive">primitive</a> type having additional usage for it's value: if object is not inherited, then <code>null</code> is shown;</li>
<li><a href="/en-US/docs/Glossary/Object">Object</a><span> : </span><code>typeof instance === "object"</code>. Special non-data but structural type for any <a href="/en-US/docs/Learn/JavaScript/Objects#The_Constructor">constructed</a> object instance also used as data structures: new <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>, new <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>, new <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a>, new <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">Set</a>, new <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap">WeakMap</a>, new <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet">WeakSet</a>, new <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">Date</a> and almost everything made with <a href="/en-US/docs/Web/JavaScript/Reference/Operators/new">new keyword</a>;</li>
<li><a href="/en-US/docs/Glossary/Function">Function</a><span> non data structure, though it also answers for typeof operator: </span><code>typeof instance === "function"</code>. This answer is done as a special shorthand for Functions, though every Function constructor is derived from Object constructor.</li>
</ul>
<p>Keep in mind the only valuable purpose of <code>typeof</code> operator usage is checking the Data Type. If we wish to check any Structural Type derived from Object it is pointless to use <code>typeof</code> for that, as we will always receive <code>"object"</code>. The indeed proper way to check what sort of Object we are using an <a href="/en-US/docs/Web/JavaScript/Reference/Operators/instanceof">instanceof</a> keyword. But even in that case there might be misconceptions.</p>
<h2 id="Wartości_prymitywne">Wartości prymitywne</h2>
<p>All types except objects define immutable values (that is, values which can't be changed). For example (and unlike in C), Strings are immutable. We refer to values of these types as "<em>primitive values</em>".</p>
<h3 id="Boolean_type">Boolean type</h3>
<p>Boolean represents a logical entity and can have two values: <code>true</code> and <code>false</code>. See <a href="/en-US/docs/Glossary/Boolean">Boolean</a> and {{jsxref("Boolean")}} for more details.</p>
<h3 id="Null_type">Null type</h3>
<p>The Null type has exactly one value: <code>null</code>. See {{jsxref("null")}} and <a href="/en-US/docs/Glossary/Null">Null</a> for more details.</p>
<h3 id="Undefined_type">Undefined type</h3>
<p>A variable that has not been assigned a value has the value <code>undefined</code>. See {{jsxref("undefined")}} and <a href="/en-US/docs/Glossary/Undefined">Undefined</a> for more details.</p>
<h3 id="Number_type">Number type</h3>
<p>ECMAScript has two built-in numeric types: <strong>Number</strong> and <strong>BigInt</strong> (see below).</p>
<p>The Number type is a <a href="http://en.wikipedia.org/wiki/Double_precision_floating-point_format">double-precision 64-bit binary format IEEE 754 value</a> (numbers between -(2<sup>53</sup> − 1) and 2<sup>53</sup> − 1). In addition to representing floating-point numbers, the number type has three symbolic values: <code>+Infinity</code>, <code>-Infinity</code>, and {{jsxref("NaN")}} ("<strong>N</strong>ot a <strong>N</strong>umber").</p>
<p>To check for the largest available value or smallest available value within {{jsxref("Infinity", "±Infinity")}}, you can use the constants {{jsxref("Number.MAX_VALUE")}} or {{jsxref("Number.MIN_VALUE")}}.</p>
<p>Starting with ECMAScript 2015, you are also able to check if a number is in the double-precision floating-point number range using {{jsxref("Number.isSafeInteger()")}} as well as {{jsxref("Number.MAX_SAFE_INTEGER")}} and {{jsxref("Number.MIN_SAFE_INTEGER")}}. Beyond this range, integers in JavaScript are not safe anymore and will be a double-precision floating point approximation of the value.</p>
<p>The number type has only one integer with two representations: <code>0</code> is represented as both <code>-0</code> and <code>+0</code>. (<code>0</code> is an alias for <code>+0</code>.) </p>
<p>In the praxis, this has almost no impact. For example, <code>+0 === -0</code> is <code>true</code>. However, you are able to notice this when you divide by zero:</p>
<pre class="brush: js notranslate">> 42 / +0
Infinity
> 42 / -0
-Infinity
</pre>
<p>Although a number often represents only its value, JavaScript provides {{jsxref("Operators/Bitwise_Operators", "binary (bitwise) operators")}}.</p>
<p>These bitwise operators can be used to represent several Boolean values within a single number using <a class="external" href="http://en.wikipedia.org/wiki/Mask_%28computing%29">bit masking</a>. However, this is usually considered a bad practice, since JavaScript offers other means to represent a set of Booleans (like an array of Booleans, or an object with Boolean values assigned to named properties). Bit masking also tends to make the code more difficult to read, understand, and maintain.</p>
<p>It may be necessary to use such techniques in very constrained environments, like when trying to cope with the limitations of local storage, or in extreme cases (such as when each bit over the network counts). This technique should only be considered when it is the last measure that can be taken to optimize size.</p>
<h3 id="BigInt_type">BigInt type</h3>
<p>The {{jsxref("BigInt")}} type is a numeric primitive in JavaScript that can represent integers with arbitrary precision. With <code>BigInt</code>s, you can safely store and operate on large integers even beyond the safe integer limit for <code>Number</code>s.</p>
<p>A <code>BigInt</code> is created by appending <code>n</code> to the end of an integer or by calling the constructor.</p>
<p>You can obtain the safest value that can be incremented with <code>Number</code>s by using the constant {{jsxref("Number.MAX_SAFE_INTEGER")}}. With the introduction of <code>BigInt</code>s, you can operate with numbers beyond the {{jsxref("Number.MAX_SAFE_INTEGER")}}.</p>
<p>This example demonstrates, where incrementing the {{jsxref("Number.MAX_SAFE_INTEGER")}} returns the expected result:</p>
<pre class="brush: js notranslate">> const x = 2n ** 53n;
9007199254740992n
> const y = x + 1n;
9007199254740993n
</pre>
<p>You can use the operators <code>+</code>, <code>*</code>, <code>-</code>, <code>**</code>, and <code>%</code> with <code>BigInt</code>s—just like with <code>Number</code>s. A <code>BigInt</code> is not strictly equal to a <code>Number</code>, but it is loosely so.</p>
<p>A <code>BigInt</code> behaves like a <code>Number</code> in cases where it is converted to <code>Boolean</code>: <code>if</code>, <code>||</code>, <code>&&</code>, <code>Boolean</code>, <code>!</code>.</p>
<p><code>BigInt</code>s cannot be operated on interchangeably with <code>Number</code>s. Instead a {{jsxref("TypeError")}} will be thrown.</p>
<h3 id="String_type">String type</h3>
<p>JavaScript's {{jsxref("String")}} type is used to represent textual data. It is a set of "elements" of 16-bit unsigned integer values. Each element in the String occupies a position in the String. The first element is at index <code>0</code>, the next at index <code>1</code>, and so on. The length of a String is the number of elements in it.</p>
<p>Unlike some programming languages (such as C), JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it.</p>
<p>However, it is still possible to create another string based on an operation on the original string. For example:</p>
<ul>
<li>A substring of the original by picking individual letters or using {{jsxref("String.substr()")}}.</li>
<li>A concatenation of two strings using the concatenation operator (<code>+</code>) or {{jsxref("String.concat()")}}.</li>
</ul>
<h4 id="Beware_of_stringly-typing_your_code!">Beware of "stringly-typing" your code!</h4>
<p>It can be tempting to use strings to represent complex data. Doing this comes with short-term benefits:</p>
<ul>
<li>It is easy to build complex strings with concatenation.</li>
<li>Strings are easy to debug (what you see printed is always what is in the string).</li>
<li>Strings are the common denominator of a lot of APIs (<a href="/en-US/docs/Web/API/HTMLInputElement" title="HTMLInputElement">input fields</a>, <a href="/en-US/docs/Storage" title="Storage">local storage</a> values, <a href="/en-US/docs/Web/API/XMLHttpRequest" title="Use XMLHttpRequest (XHR) objects to interact with servers. You can retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without disrupting what the user is doing."><code>XMLHttpRequest</code></a> responses when using <code>responseText</code>, etc.) and it can be tempting to only work with strings.</li>
</ul>
<p>With conventions, it is possible to represent any data structure in a string. This does not make it a good idea. For instance, with a separator, one could emulate a list (while a JavaScript array would be more suitable). Unfortunately, when the separator is used in one of the "list" elements, then, the list is broken. An escape character can be chosen, etc. All of this requires conventions and creates an unnecessary maintenance burden.</p>
<p>Use strings for textual data. When representing complex data, parse strings and use the appropriate abstraction.</p>
<h3 id="Symbol_type">Symbol type</h3>
<p>Symbols are new to JavaScript in ECMAScript 2015. A Symbol is a <strong>unique</strong> and <strong>immutable</strong> primitive value and may be used as the key of an Object property (see below). In some programming languages, Symbols are called "atoms".</p>
<p>For more details see <a href="/en-US/docs/Glossary/Symbol">Symbol</a> and the {{jsxref("Symbol")}} object wrapper in JavaScript.</p>
<h2 id="Obiekty">Obiekty</h2>
<p>In computer science, an object is a value in memory which is possibly referenced by an <a href="/en-US/docs/Glossary/Identifier">identifier</a>.</p>
<h3 id="Properties">Properties</h3>
<p>In JavaScript, objects can be seen as a collection of properties. With the <a href="/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals#Object_literals">object literal syntax</a>, a limited set of properties are initialized; then properties can be added and removed. Property values can be values of any type, including other objects, which enables building complex data structures. Properties are identified using <em>key</em> values. A <em>key</em> value is either a String or a Symbol value.</p>
<p>There are two types of object properties which have certain attributes: The <em>data</em> property and the <em>accessor</em> property.</p>
<h4 id="Data_property">Data property</h4>
<p>Associates a key with a value, and has the following attributes:</p>
<table class="standard-table">
<caption>Attributes of a data property</caption>
<thead>
<tr>
<th scope="col">Attribute</th>
<th scope="col">Type</th>
<th scope="col">Description</th>
<th scope="col">Default value</th>
</tr>
</thead>
<tbody>
<tr>
<td>[[Value]]</td>
<td>Any JavaScript type</td>
<td>The value retrieved by a get access of the property.</td>
<td><code>undefined</code></td>
</tr>
<tr>
<td>[[Writable]]</td>
<td>Boolean</td>
<td>If <code>false</code>, the property's [[Value]] cannot be changed.</td>
<td><code>false</code></td>
</tr>
<tr>
<td>[[Enumerable]]</td>
<td>Boolean</td>
<td>
<p>If <code>true</code>, the property will be enumerated in <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for...in</a> loops.<br>
See also <a href="/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties">Enumerability and ownership of properties</a>.</p>
</td>
<td><code>false</code></td>
</tr>
<tr>
<td>[[Configurable]]</td>
<td>Boolean</td>
<td>If <code>false</code>, the property cannot be deleted, cannot be changed to an accessor property, and attributes other than [[Value]] and [[Writable]] cannot be changed.</td>
<td><code>false</code></td>
</tr>
</tbody>
</table>
<table class="standard-table">
<caption>Obsolete attributes (as of ECMAScript 3, renamed in ECMAScript 5)</caption>
<thead>
<tr>
<th scope="col">Attribute</th>
<th scope="col">Type</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Read-only</td>
<td>Boolean</td>
<td>Reversed state of the ES5 [[Writable]] attribute.</td>
</tr>
<tr>
<td>DontEnum</td>
<td>Boolean</td>
<td>Reversed state of the ES5 [[Enumerable]] attribute.</td>
</tr>
<tr>
<td>DontDelete</td>
<td>Boolean</td>
<td>Reversed state of the ES5 [[Configurable]] attribute.</td>
</tr>
</tbody>
</table>
<h4 id="Accessor_property">Accessor property</h4>
<p>Associates a key with one of two accessor functions (<code>get</code> and <code>set</code>) to retrieve or store a value, and has the following attributes:</p>
<table class="standard-table">
<caption>Attributes of an accessor property</caption>
<thead>
<tr>
<th scope="col">Attribute</th>
<th scope="col">Type</th>
<th scope="col">Description</th>
<th scope="col">Default value</th>
</tr>
</thead>
<tbody>
<tr>
<td>[[Get]]</td>
<td>Function object or <code>undefined</code></td>
<td>The function is called with an empty argument list and retrieves the property value whenever a get access to the value is performed.<br>
See also <a href="/en-US/docs/Web/JavaScript/Reference/Operators/get"><code>get</code></a>.</td>
<td><code>undefined</code></td>
</tr>
<tr>
<td>[[Set]]</td>
<td>Function object or <code>undefined</code></td>
<td>The function is called with an argument that contains the assigned value and is executed whenever a specified property is attempted to be changed.<br>
See also <a href="/en-US/docs/Web/JavaScript/Reference/Operators/set"><code>set</code></a>.</td>
<td><code>undefined</code></td>
</tr>
<tr>
<td>[[Enumerable]]</td>
<td>Boolean</td>
<td>If <code>true</code>, the property will be enumerated in <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for...in</a> loops.</td>
<td><code>false</code></td>
</tr>
<tr>
<td>[[Configurable]]</td>
<td>Boolean</td>
<td>If <code>false</code>, the property can't be deleted and can't be changed to a data property.</td>
<td><code>false</code></td>
</tr>
</tbody>
</table>
<div class="note">
<p><strong>Note: </strong>Attribute is usually used by JavaScript engine, so you can't directly access it (see more about {{jsxref("Object.defineProperty()")}}). That's why the attribute is put in double square brackets instead of single.</p>
</div>
<h3 id="Normal_objects_and_functions">"Normal" objects, and functions</h3>
<p>A JavaScript object is a mapping between <em>keys</em> and <em>values</em>. Keys are strings (or {{jsxref("Symbol")}}s), and <em>values</em> can be anything. This makes objects a natural fit for <a class="external" href="http://en.wikipedia.org/wiki/Hash_table">hashmaps</a>.</p>
<p>Functions are regular objects with the additional capability of being <em>callable</em>.</p>
<h3 id="Dates">Dates</h3>
<p>When representing dates, the best choice is to use the built-in <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"><code>Date</code> utility</a> in JavaScript.</p>
<h3 id="Indexed_collections_Arrays_and_typed_Arrays">Indexed collections: Arrays and typed Arrays</h3>
<p><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array" title="Array">Arrays</a> are regular objects for which there is a particular relationship between integer-key-ed properties and the <code>length</code> property.</p>
<p>Additionally, arrays inherit from <code>Array.prototype</code>, which provides to them a handful of convenient methods to manipulate arrays. For example, <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf" title="en/JavaScript/Reference/Global_Objects/Array/indexOf">indexOf</a></code> (searching a value in the array) or <code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/push" title="en/JavaScript/Reference/Global_Objects/Array/push">push</a></code> (adding an element to the array), and so on. This makes Arrays a perfect candidate to represent lists or sets.</p>
<p><a href="/en-US/docs/Web/JavaScript/Typed_arrays">Typed Arrays</a> are new to JavaScript with ECMAScript 2015, and present an array-like view of an underlying binary data buffer. The following table helps determine the equivalent C data types:</p>
<table class="standard-table">
<thead>
<tr>
<th class="header" scope="col">Type</th>
<th class="header" scope="col">Value Range</th>
<th class="header" scope="col">Size in bytes</th>
<th class="header" scope="col">Description</th>
<th class="header" scope="col">Web IDL type</th>
<th class="header" scope="col">Equivalent C type</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{jsxref("Int8Array")}}</td>
<td><code>-128</code> to <code>127</code></td>
<td>1</td>
<td>8-bit two's complement signed integer</td>
<td><code>byte</code></td>
<td><code>int8_t</code></td>
</tr>
<tr>
<td>{{jsxref("Uint8Array")}}</td>
<td><code>0</code> to <code>255</code></td>
<td>1</td>
<td>8-bit unsigned integer</td>
<td><code>octet</code></td>
<td><code>uint8_t</code></td>
</tr>
<tr>
<td>{{jsxref("Uint8ClampedArray")}}</td>
<td><code>0</code> to <code>255</code></td>
<td>1</td>
<td>8-bit unsigned integer (clamped)</td>
<td><code>octet</code></td>
<td><code>uint8_t</code></td>
</tr>
<tr>
<td>{{jsxref("Int16Array")}}</td>
<td><code>-32768</code> to <code>32767</code></td>
<td>2</td>
<td>16-bit two's complement signed integer</td>
<td><code>short</code></td>
<td><code>int16_t</code></td>
</tr>
<tr>
<td>{{jsxref("Uint16Array")}}</td>
<td><code>0</code> to <code>65535</code></td>
<td>2</td>
<td>16-bit unsigned integer</td>
<td><code>unsigned short</code></td>
<td><code>uint16_t</code></td>
</tr>
<tr>
<td>{{jsxref("Int32Array")}}</td>
<td><code>-2147483648</code> to <code>2147483647</code></td>
<td>4</td>
<td>32-bit two's complement signed integer</td>
<td><code>long</code></td>
<td><code>int32_t</code></td>
</tr>
<tr>
<td>{{jsxref("Uint32Array")}}</td>
<td><code>0</code> to <code>4294967295</code></td>
<td>4</td>
<td>32-bit unsigned integer</td>
<td><code>unsigned long</code></td>
<td><code>uint32_t</code></td>
</tr>
<tr>
<td>{{jsxref("Float32Array")}}</td>
<td><code>1.2</code><span>×</span><code>10<sup>-38</sup></code> to <code>3.4</code><span>×</span><code>10<sup>38</sup></code></td>
<td>4</td>
<td>32-bit IEEE floating point number (7 significant digits e.g., <code>1.1234567</code>)</td>
<td><code>unrestricted float</code></td>
<td><code>float</code></td>
</tr>
<tr>
<td>{{jsxref("Float64Array")}}</td>
<td><code>5.0</code><span>×</span><code>10<sup>-324</sup></code> to <code>1.8</code><span>×</span><code>10<sup>308</sup></code></td>
<td>8</td>
<td>64-bit IEEE floating point number (16 significant digits e.g., <code>1.123...15</code>)</td>
<td><code>unrestricted double</code></td>
<td><code>double</code></td>
</tr>
<tr>
<td>{{jsxref("BigInt64Array")}}</td>
<td><code>-2<sup>63</sup></code> to <code>2<sup>63</sup>-1</code></td>
<td>8</td>
<td>64-bit two's complement signed integer</td>
<td><code>bigint</code></td>
<td><code>int64_t (signed long long)</code></td>
</tr>
<tr>
<td>{{jsxref("BigUint64Array")}}</td>
<td><code>0</code> to <code>2<sup>64</sup>-1</code></td>
<td>8</td>
<td>64-bit unsigned integer</td>
<td><code>bigint</code></td>
<td><code>uint64_t (unsigned long long)</code></td>
</tr>
</tbody>
</table>
<h3 id="Keyed_collections_Maps_Sets_WeakMaps_WeakSets">Keyed collections: Maps, Sets, WeakMaps, WeakSets</h3>
<p>These data structures, introduced in ECMAScript Edition 6, take object references as keys. {{jsxref("Set")}} and {{jsxref("WeakSet")}} represent a set of objects, while {{jsxref("Map")}} and {{jsxref("WeakMap")}} associate a value to an object.</p>
<p>The difference between <code>Map</code>s and <code>WeakMap</code>s is that in the former, object keys can be enumerated over. This allows garbage collection optimizations in the latter case.</p>
<p>One could implement <code>Map</code>s and <code>Set</code>s in pure ECMAScript 5. However, since objects cannot be compared (in the sense of <code><</code> "less than", for instance), look-up performance would necessarily be linear. Native implementations of them (including <code>WeakMap</code>s) can have look-up performance that is approximately logarithmic to constant time.</p>
<p>Usually, to bind data to a DOM node, one could set properties directly on the object, or use <code>data-*</code> attributes. This has the downside that the data is available to any script running in the same context. <code>Map</code>s and <code>WeakMap</code>s make it easy to <em>privately</em> bind data to an object.</p>
<h3 id="Structured_data_JSON">Structured data: JSON</h3>
<p>JSON (<strong>J</strong>ava<strong>S</strong>cript <strong>O</strong>bject <strong>N</strong>otation) is a lightweight data-interchange format, derived from JavaScript, but used by many programming languages. JSON builds universal data structures.</p>
<p>See <a href="/en-US/docs/Glossary/JSON">JSON</a> and {{jsxref("JSON")}} for more details.</p>
<h3 id="More_objects_in_the_standard_library">More objects in the standard library</h3>
<p>JavaScript has a standard library of built-in objects.</p>
<p>Please have a look at the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects">reference</a> to find out about more objects.</p>
<h2 id="Określanie_typu_za_pomocą_operatora_typeof">Określanie typu za pomocą operatora <code>typeof</code></h2>
<p>Operator <code>typeof</code> może być pomocny przy określeniu typu twojej zmiennej.</p>
<p>Więcej szczegółów znajdziecie na stronie poświęconej operatorowi <code>typeof</code>.</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-ecmascript-data-types-and-values', 'ECMAScript Data Types and Values')}}</td>
</tr>
</tbody>
</table>
<h2 id="See_also">See also</h2>
<ul>
<li><a class="link-https" href="https://github.com/nzakas/computer-science-in-javascript/">Nicholas Zakas collection of common data structure and common algorithms in JavaScript.</a></li>
<li><a href="https://github.com/monmohan/DataStructures_In_Javascript" title="https://github.com/monmohan/DataStructures_In_Javascript">Search Tre(i)es implemented in JavaScript</a></li>
</ul>
|