Question

I have been reading a book that deals with writing single page applications in Javascript and I ran through this piece of code:

//begin merge changes into anchor map
        KEYVAL:
        for(key_name in arg_map){
            if(arg_map.hasOwnProperty(key_name)){
                //skip dependent keys during iteration
                if(key_name.indexOf('_') === 0){
                    continue KEYVAL;
                }

                //update independent key valie
                anchor_map_revise[key_name] = arg_map[key_name];

                //update matching dependent key
                key_name_dep = '_' + key_name;
                if(arg_map[key_name_dep]){
                    anchor_map_revise[key_name_dep] = arg_map[key_name_dep];
                }
                else{
                    delete anchor_map_revise[key_name_dep];
                    delete anchor_map_revise['_s' + key_name_dep];
                }
            }
        }

And the problem is that I don't know what that 'KEYVAL:' does. Can someone please explain and possibly reference me to some documentation for that specific notation? Thank you.

Was it helpful?

Solution

KEYVAL: here is a label. This is where the execution jumps at the continue KEYVAL; statement.

See the MDN on continue :

The continue statement can include an optional label that allows the program to jump to the next iteration of a labelled loop statement instead of the current loop. In this case, the continue statement needs to be nested within this labelled statement.

This is mostly used when you want to deal with nested loops as it lets you choose the loop level to which to jump. In your code, it looks useless, you can remove the label and keep a simple continue statement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top