Odkaz na prohlášení JavaScriptu
JavaScript prohlášení
V HTML jsou příkazy JavaScriptu „instrukce“, které mají být „provedeny“ webovým prohlížečem.
Tento příkaz říká prohlížeči, aby napsal "Hello Dolly." uvnitř prvku HTML s id="demo":
Příklad
document.getElementById("demo").innerHTML = "Hello Dolly.";
Výukový program o příkazech naleznete v našem výukovém programu příkazů JavaScriptu .
Identifikátory příkazů JavaScript
Příkazy JavaScriptu často začínají identifikátorem příkazu k identifikaci akce JavaScriptu, která má být provedena.
Identifikátory příkazů jsou vyhrazená slova a nelze je použít jako názvy proměnných (nebo jakékoli jiné věci).
V následující tabulce jsou uvedeny všechny identifikátory příkazů JavaScript:
Statement | Description |
---|---|
break | Exits a switch or a loop |
class | Declares a class |
const | Declares a variable with a constant value |
continue | Breaks one iteration (in the loop) if a specified condition occurs, and continues with the next iteration in the loop |
debugger | Stops the execution of JavaScript, and calls (if available) the debugging function |
do ... while | Executes a block of statements and repeats the block while a condition is true |
for | Loops through a block of code a number of times |
for ... in | Loops through the properties of an object |
for ... of | Loops through the values of an iterable object |
function | Declares a function |
if ... else ... else if | Marks a block of statements to be executed depending on a condition |
let | Declares a variable |
return | Stops the execution of a function and returns a value from that function |
switch | Marks a block of statements to be executed depending on different cases |
throw | Throws (generates) an error |
try ... catch ... finally | Marks the block of statements to be executed when an error occurs in a try block, and implements error handling |
var | Declares a variable |
while | Marks a block of statements to be executed while a condition is true |