Is there a JavaScript equivalent of the Python pass statement that does nothing?

Is there a JavaScript equivalent of the Python pass statement that does nothing?

Pythons pass mainly exists because in Python whitespace matters within a block. In Javascript, the equivalent would be putting nothing within the block, i.e. {}.

use //pass like pythons pass

like:

if(condition){
   //pass
}

This is equivalent to leaving the block with nothing in it, but is good for readability reasons.

reference from https://eslint.org/docs/rules/no-empty

Is there a JavaScript equivalent of the Python pass statement that does nothing?

pythons pass is required for empty blocks.

try:
    # something
except Exception:
    pass

In javascript you can simply catch an empty block

try {
    // some code
} catch (e) {
    // This here can be empty
}

Leave a Reply

Your email address will not be published. Required fields are marked *