- To label JavaScript statements you precede the statements with a label name and a colon.
- With a label reference, the break statement can be used to come out of any code block.
- A code block is a block of code between { and }
Code:-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<input type="button" onclick="fun_label()" value="Test label and break">
<script>
function fun_label()
{
golabel:
{
var i = 10;
var j = 15;
break golabel;
var k = 100; //Will not execute
}
var x = 475;
alert(i);
alert(j);
alert(k);
alert(x);
}
</script>
</body>
</html>
Label and break statement :- genius student
Reviewed by Network security
on
October 27, 2019
Rating:
No comments: