Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this syntax mean which likes `functionName: {}`?

Tags:

javascript

I have found a piece of code in my company's project like the following:

while(condition){        
        code...

        reloop: {
            if(somethingIsTrue) {
                break reloop;
            }
        }

        code...
}

I don't understand what reloop does, can anyone give a simple explanation?

like image 263
Allen Avatar asked Oct 06 '15 15:10

Allen


People also ask

What does () => mean in JavaScript?

It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.

What does -> int mean in Python?

the -> int just tells that f() returns an integer (but it doesn't force the function to return an integer). It is called a return annotation, and can be accessed as f. __annotations__['return'] . Python also supports parameter annotations: def f(x: float) -> int: return int(x)

What is function syntax?

Arguments typically have some restrictions on the expression used for that argument. For example, the input argument to the INDEX function can only be an object name. Depending on the function, one or many data objects can be used for an input argument for one function evaluation.

What is this in arrow function?

In regular functions the this keyword represented the object that called the function, which could be the window, the document, a button or whatever. With arrow functions the this keyword always represents the object that defined the arrow function. Let us take a look at two examples to understand the difference.


1 Answers

reloop: is a label. They are rarely used, and serve a very specific purpose: they let you break or continue outer loops from inner loops.

The article on MDN about labels explains this better.

Note that labels are very rarely used, and most of the time needing a label hints that your code is unclear, and should be restructured. I have never, not even once, used a label in javascript.

Avoid them unless they are truly the only clean solution to piece of code that proves difficult to write. Prefer, instead, splitting code into functions that you can return from.

like image 164
slezica Avatar answered Sep 30 '22 06:09

slezica