JavaScript label statement17 Mar 2025 | 3 min read JavaScript label is a statement used to prefix a label as an identifier. You can specify the label by any name other than the reserved words. It is simply used with a colon (:) in code. A label can be used with a break or continue statement to control the flow of the code more precisely. The label is applied to a block of code or a statement. Using some examples, we will learn how to define and use the label statement in JavaScript. SyntaxParameterslabel: It is a JavaScript identifier. Define it by any name that is not a reserved keyword. Statements: It is a JavaScript statement, where break is simply used with the labelled statement and continue with looping labelled statement. ExamplesLet's understand the JavaScript label that how it works and helps to break or continue with the looping statement with the help of different examples. Example: Label with for loop to breakIn this example, we will define two labels by the name innerloop and outerloop, which is used with for loop to break the execution of the loop for a specified condition. Copy Code Output Entering the loop! Outerloop i: 0 Innerloop execution j: 0 Innerloop execution j: 1 Innerloop execution j: 2 Innerloop execution j: 3 Break innermost loop when j>3 Outerloop i: 1 Innerloop execution j: 0 Innerloop execution j: 1 Innerloop execution j: 2 Innerloop execution j: 3 Break innermost loop when j>3 Outerloop i: 2 Break Innerloop when i=2 Outerloop i: 3 Innerloop execution j: 0 Innerloop execution j: 1 Innerloop execution j: 2 Innerloop execution j: 3 Break Innerloop when j>3 Outerloop i: 4 Break Outerloop when i=4 Exit from all loops! Example: Label with for loop to continueIn this example, we will again define two labels by the name innerloop and outerloop. But now they are used with for loop to continue the execution of the loop when the specified condition occurs. Copy Code Output Entering the loop! Outerloop i: 0 Innerloop execution j: 0 Innerloop execution j: 1 Innerloop execution j: 2 Continue Outerloop when j=3 Outerloop i: 1 Innerloop execution j: 0 Innerloop execution j: 1 Innerloop execution j: 2 Continue Outerloop when j=3 Outerloop i: 2 Innerloop execution j: 0 Innerloop execution j: 1 Innerloop execution j: 2 Continue Outerloop when j=3 Outerloop i: 3 Continue Innerloop when i>2 Continue Innerloop when i>2 Continue Innerloop when i>2 Continue Innerloop when i>2 Exit from all loops! Basically, a label statement in JavaScript controls the flow of the program. JavaScript programmers use labels rarely now. Next TopicWho-created-javascript |
What is a Hash Table in JavaScript? In JavaScript, a Hash table, also known as a hash map, is considered a data structure that helps us store key-value pairs more efficiently. Using hash functions, we can map keys to indices in an array, which allows for faster...
8 min read
The JavaScript notification function shows the desktop notifications to users using the Notification API. We can use it to know the message or information of the functionality of JavaScript. Permissions for Notifications The Notification API strongly enforces two security aspects by default. JavaScript can easily exploit it. Firstly,...
3 min read
Introduction to Dictionaries in JavaScript JavaScript is a programming language that is utilized for web development and it does so with great flexibility. A dictionary is also called an object and it is one of the basic data structures. The use of dictionaries is the storage and...
7 min read
. In this article, we will understand how to create Auto calculate price form in JavaScript. In this, we will learn some basics of this concept and some examples of Autocomplete form with the help of JavaScript. What do you mean by JavaScript? JavaScript abbreviated as JS. It...
6 min read
Anagrams are an interesting notion in linguistics and computer science. In brief, an anagram is an arrangement of the letters of a word or a phrase so that one can form a new word or a phrase using those letters, but the letters should be...
8 min read
What is Discord? Discord is a free app that allows users to communicate with others in real-time using text, voice, or video chat. It is a popular way for people with similar interests to connect online and is especially popular among the gamers. It is available on many...
6 min read
The jQuery JavaScript library offers jQuery DataTable, an intelligent and powerful plugin for upgrading HTML tables. It is an extremely adaptable application designed to improve data accessibility in HTML tables by displaying information in tables and adding interactions. jQuery DataTables makes it easy to add sophisticated functionality...
13 min read
An Armstrong number is a special integer in which the sum of its digits, raised to the power of the number's length, is equal to the number. For instance, 153 is an Armstrong number since 1^3 + 5^3 + 3^3 = 153. Definition of Armstrong Number An Armstrong...
5 min read
The JavaScript "m{X,}" quantifier works on any text of a series (m) with minimum X times. The {X,} is represented as a number and can be matched to string at least x number using the quantifier function in JavaScript. The regex quantifier operates in a...
4 min read
Arrays are fundamental data structures in JavaScript, providing a flexible way to store multiple values in a single variable. One common question among JavaScript developers is whether arrays can be extended once they are created. Let's delve into this topic to understand the dynamics of extending...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India