Інструкції та оголошення

Застосунки JavaScript складаються з інструкцій з відповідним синтаксисом. Одна інструкція може займати декілька рядків. Декілька інструкцій можуть розташовуватись на одному рядку, якщо кожна інструкція відділена крапкою з комою. Це не ключове слово, а група ключових слів.

Інструкції та оголошення за категоріями

Список в алфавітному порядку дивіться на бічній панелі ліворуч.

Потік керування

Block
Блок використовують, щоб згрупувати нуль чи більше інструкцій. Блок позначається парою фігурних дужок.
break
Перериває поточний цикл, switch або помічену інструкцію та передає контроль програми у інструкцію, наступну за перерваною інструкцією.
continue
Перериває виконання інструкцій у поточній ітерації поточного або поміченого циклу та продовжує виконання циклу з наступної ітерації.
Empty
Порожній оператор використовується, щоб не надавати інструкцію там, де синтаксис JavaScript її очікує.
if...else
Виконує інструкцію, якщо вказана умова дорівнює true. Якщо умова дорівнює false, виконується інша інструкція.
switch
Обчислює вираз, шукаючі збіг значення виразу з блоком case, та виконує інструкції, асоційовані з цим блоком.
throw
Викидає визначений користувачем виняток.
try...catch
Позначає блок інструкцій, які необхідно спробувати виконати, та визначає відповідь у випадку, якщо викидається виняток.

Оголошення

var
Оголошує змінну, необов'язково ініціалізуючи її значенням.
let
Оголошує локальну змінну блочної області видимості, необов'язково ініціалізуючи її значенням.
const
Оголошує іменовану константу, доступну лише для читання.

Функції та класи

function
Оголошує функцію з вказаними параметрами.
function*
Функції-генератори спрощують написання ітераторів.
async function
Оголошує асинхронну функцію з вказаними параметрами.
return
Вказує значення, яке має повернути функція.
class
Оголошує клас.

Перебори

do...while
Створює цикл, що виконує вказану інструкцію, яка виконується, доки перевірочна умова не стане дорівнювати false. Умова обчислюється після виконання інструкції, в результаті вказана інструкція виконується принаймні один раз.
for
Створює цикл, що складається з трьох необов'язкових виразів, записаних у дужках та розділених крапками з комами, після яких вказується інструкція для виконання циклом.
for each...in
Перебирає вказаною змінною усі значення властивостей об'єкта. Для кожної окремої властивості виконується вказана інструкція.
for...in
Перебирає перелічувані властивості об'єкта у довільному порядку. Для кожної окремої властивості можуть виконуватись інструкції.
for...of
Перебирає ітерабельні об'єкти (в тому числі масиви, подібні до масивів об'єкти, ітератори та генератори), викликаючи користувацький хук до ітерацій з інструкціями, що виконуватимуться для значення кожної окремої властивості.
for await...of
Перебирає асинхронні ітерабельні об'єкти, подібні до масивів об'єкти, ітератори та генератори, викликаючи користувацький хук до ітерацій з інструкціями, що виконуватимуться для значення кожної окремої властивості.
while
Створює цикл, який виконує вказану інструкцію, доки перевірочна умова дорівнює true. Умова обчислюється перед виконанням інструкції.

Інші

debugger
Запускає будь-яку доступну налагоджувальну функціональність. Якщо налагоджувальна функціональність недоступна, цей оператор не матиме ефекту.
export
Використовується для експорту функцій, щоб зробити їх доступними для імпорту у зовнішні модулі та інші скрипти.
import
Використовується для імпорту функцій, експортованих з зовнішнього модуля чи іншого скрипта.
import.meta
Об'єкт, що відкриває залежні від контексту метадані про модуль JavaScript.
label
Надає інструкцію з ідентифікатором, на який можна посилатись при використанні інструкцій break або continue.
with
Розширює ланцюжок областей видимості для інструкції.

Специфікації

Специфікація
ECMAScript (ECMA-262)
The definition of 'ECMAScript Language: Statements and Declarations' in that specification.

Сумісність з веб-переглядачами

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
async functionChrome Full support 55Edge Full support 15Firefox Full support 52IE No support NoOpera Full support 42Safari Full support 10.1WebView Android Full support 55Chrome Android Full support 55Firefox Android Full support 52Opera Android Full support 42Safari iOS Full support 10.3Samsung Internet Android Full support 6.0nodejs Full support 7.6.0
Full support 7.6.0
Full support 7.0.0
Disabled
Disabled From version 7.0.0: this feature is behind the --harmony runtime flag.
blockChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 11Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
breakChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
classChrome Full support 49
Full support 49
No support 42 — 49
Notes
Notes Strict mode is required.
No support 42 — 49
Disabled
Disabled From version 42 until version 49 (exclusive): this feature is behind the Experimental JavaScript preference (needs to be set to Enabled). To change preferences in Chrome, visit chrome://flags.
Edge Full support 13Firefox Full support 45IE No support NoOpera Full support 36
Full support 36
No support 29 — 36
Notes
Notes Strict mode is required.
No support 29 — 36
Disabled
Disabled From version 29 until version 36 (exclusive): this feature is behind the Experimental JavaScript preference (needs to be set to Enabled).
Safari Full support 10.1WebView Android Full support 49
Full support 49
No support 42 — 49
Notes
Notes Strict mode is required.
Chrome Android Full support 49
Full support 49
No support 42 — 49
Notes
Notes Strict mode is required.
No support 42 — 49
Disabled
Disabled From version 42 until version 49 (exclusive): this feature is behind the Experimental JavaScript preference (needs to be set to Enabled). To change preferences in Chrome, visit chrome://flags.
Firefox Android Full support 45Opera Android Full support 36
Full support 36
No support 29 — 36
Notes
Notes Strict mode is required.
No support 29 — 36
Disabled
Disabled From version 29 until version 36 (exclusive): this feature is behind the Experimental JavaScript preference (needs to be set to Enabled).
Safari iOS Full support 10.3Samsung Internet Android Full support 5.0
Full support 5.0
No support 4.0 — 5.0
Notes
Notes Strict mode is required.
nodejs Full support 6.0.0
constChrome Full support 21Edge Full support 12Firefox Full support 36
Notes
Full support 36
Notes
Notes Prior to Firefox 13, const is implemented, but re-assignment is not failing.
Notes Prior to Firefox 46, a TypeError was thrown on redeclaration instead of a SyntaxError.
IE Full support 11Opera Full support 9Safari Full support 5.1WebView Android Full support ≤37Chrome Android Full support 25Firefox Android Full support 36
Notes
Full support 36
Notes
Notes Prior to Firefox 13, const is implemented, but re-assignment is not failing.
Notes Prior to Firefox 46, a TypeError was thrown on redeclaration instead of a SyntaxError.
Opera Android Full support 10.1Safari iOS Full support 6Samsung Internet Android Full support 1.5nodejs Full support 6.0.0
continueChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
debuggerChrome Full support 5Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 10Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
do...whileChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
Empty statement (;)Chrome Full support 3Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
exportChrome Full support 61Edge Full support 16
Full support 16
Full support 15
Disabled
Disabled From version 15: this feature is behind the Experimental JavaScript Features preference.
Firefox Full support 60
Full support 60
No support 54 — 60
Disabled
Disabled From version 54 until version 60 (exclusive): this feature is behind the dom.moduleScripts.enabled preference. To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 48Safari Full support 10.1WebView Android No support NoChrome Android Full support 61Firefox Android Full support 60
Full support 60
No support 54 — 60
Disabled
Disabled From version 54 until version 60 (exclusive): this feature is behind the dom.moduleScripts.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android Full support 45Safari iOS Full support 10.3Samsung Internet Android Full support 8.0nodejs Full support 13.2.0
Notes
Full support 13.2.0
Notes
Notes Modules must either have a filename ending in .mjs, or the nearest parent package.json file must contain "type": "module". See Node's ECMAScript Modules documentation for more details.
Full support 12.0.0
Notes Disabled
Notes Modules must either have a filename ending in .mjs, or the nearest parent package.json file must contain "type": "module". See Node's ECMAScript Modules documentation for more details.
Disabled From version 12.0.0: this feature is behind the --experimental-modules runtime flag.
Full support 8.5.0
Notes Disabled
Notes Module filenames must end with .mjs, not .js. See Node's ECMAScript Modules documentation for more details.
Disabled From version 8.5.0: this feature is behind the --experimental-modules runtime flag.
forChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
for await...ofChrome Full support 63Edge Full support 79Firefox Full support 57IE No support NoOpera Full support 50Safari Full support 11WebView Android Full support 63Chrome Android Full support 63Firefox Android Full support 57Opera Android Full support 46Safari iOS Full support 11Samsung Internet Android Full support 8.0nodejs Full support 10.0.0
Full support 10.0.0
No support 8.10.0 — 10.0.0
Disabled
Disabled From version 8.10.0 until version 10.0.0 (exclusive): this feature is behind the --harmony-async-iteration runtime flag.
for...inChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 6Opera Full support 2Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
for...ofChrome Full support 38Edge Full support 12Firefox Full support 13
Notes
Full support 13
Notes
Notes Prior to Firefox 51, using the for...of loop construct with the const keyword threw a SyntaxError ("missing = in const declaration").
IE No support NoOpera Full support 25Safari Full support 7WebView Android Full support 38Chrome Android Full support 38Firefox Android Full support 14
Notes
Full support 14
Notes
Notes Prior to Firefox 51, using the for...of loop construct with the const keyword threw a SyntaxError ("missing = in const declaration").
Opera Android Full support 25Safari iOS Full support 7Samsung Internet Android Full support 3.0nodejs Full support 0.12
functionChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
function*Chrome Full support 39Edge Full support 13Firefox Full support 26IE No support NoOpera Full support 26Safari Full support 10WebView Android Full support 39Chrome Android Full support 39Firefox Android Full support 26Opera Android Full support 26Safari iOS Full support 10Samsung Internet Android Full support 4.0nodejs Full support 4.0.0
Full support 4.0.0
Full support 0.12
Disabled
Disabled From version 0.12: this feature is behind the --harmony runtime flag.
if...elseChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
importChrome Full support 61Edge Full support 16
Full support 16
Full support 15
Disabled
Disabled From version 15: this feature is behind the Experimental JavaScript Features preference.
Firefox Full support 60
Full support 60
No support 54 — 60
Disabled
Disabled From version 54 until version 60 (exclusive): this feature is behind the dom.moduleScripts.enabled preference. To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 48Safari Full support 10.1WebView Android Full support 61Chrome Android Full support 61Firefox Android Full support 60
Full support 60
No support 54 — 60
Disabled
Disabled From version 54 until version 60 (exclusive): this feature is behind the dom.moduleScripts.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android Full support 45Safari iOS Full support 10.3Samsung Internet Android Full support 8.0nodejs Full support 13.2.0
Notes
Full support 13.2.0
Notes
Notes Modules must either have a filename ending in .mjs, or the nearest parent package.json file must contain "type": "module". See Node's ECMAScript Modules documentation for more details.
Full support 12.0.0
Notes Disabled
Notes Modules must either have a filename ending in .mjs, or the nearest parent package.json file must contain "type": "module". See Node's ECMAScript Modules documentation for more details.
Disabled From version 12.0.0: this feature is behind the --experimental-modules runtime flag.
Full support 8.5.0
Notes Disabled
Notes Module filenames must end with .mjs, not .js. See Node's ECMAScript Modules documentation for more details.
Disabled From version 8.5.0: this feature is behind the --experimental-modules runtime flag.
import.metaChrome Full support 64Edge Full support 79Firefox Full support 62IE No support NoOpera Full support 51Safari Full support 11.1WebView Android Full support 64Chrome Android Full support 64Firefox Android Full support 62Opera Android Full support 47Safari iOS Full support 12Samsung Internet Android Full support 9.0nodejs Full support 10.4.0
labelChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
letChrome Full support 49
Full support 49
No support 48 — 49
Notes Disabled
Notes Support outside of strict mode.
Disabled From version 48 until version 49 (exclusive): this feature is behind the Enable Experimental JavaScript Features preference. To change preferences in Chrome, visit chrome://flags.
No support 41 — 49
Notes
Notes Strict mode is required.
Edge Full support 14
Full support 14
No support 12 — 14
Notes
Notes In Edge 12 and 13, let within a for loop initializer does not create a separate variable for each loop iteration as defined by ES2015. Instead, it behaves as though the loop were wrapped in a scoping block with the let immediately before the loop.
Firefox Full support 44
Notes
Full support 44
Notes
Notes Prior to Firefox 44, let is only available to code blocks in HTML wrapped in a <script type="application/javascript;version=1.7"> block (or higher version) and has different semantics (e.g. no temporal dead zone).
Notes Prior to Firefox 46, a TypeError is thrown on redeclaration instead of a SyntaxError.
Notes Firefox 54 adds support of let in workers.
IE Partial support 11
Notes
Partial support 11
Notes
Notes In Internet Explorer, let within a for loop initializer does not create a separate variable for each loop iteration as defined by ES2015. Instead, it behaves as though the loop were wrapped in a scoping block with the let immediately before the loop.
Opera Full support 17Safari Full support 10WebView Android Full support 49
Full support 49
No support 41 — 49
Notes
Notes Strict mode is required.
Chrome Android Full support 49
Full support 49
No support 48 — 49
Notes Disabled
Notes Support outside of strict mode.
Disabled From version 48 until version 49 (exclusive): this feature is behind the Enable Experimental JavaScript Features preference. To change preferences in Chrome, visit chrome://flags.
No support 41 — 49
Notes
Notes Strict mode is required.
Firefox Android Full support 44
Notes
Full support 44
Notes
Notes Prior to Firefox 44, let is only available to code blocks in HTML wrapped in a <script type="application/javascript;version=1.7"> block (or higher version) and has different semantics (e.g. no temporal dead zone).
Notes Prior to Firefox 46, a TypeError is thrown on redeclaration instead of a SyntaxError.
Notes Firefox 54 adds support of let in workers.
Opera Android Full support 18Safari iOS Full support 10Samsung Internet Android Full support 5.0
Full support 5.0
No support 4.0 — 5.0
Notes
Notes Strict mode is required.
nodejs Full support 6.0.0
returnChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
switchChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
throwChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
try...catchChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
varChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
whileChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100
with
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100

Legend

Full support  
Full support
Partial support  
Partial support
No support  
No support
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

Див. також