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

前端 未结 9 659
感情败类
感情败类 2021-02-06 20:02

I am looking for a JavaScript equivalent of the Python:

pass statement that does not run the function of the ... notation?

Is the

相关标签:
9条回答
  • 2021-02-06 20:49

    In some cases pass can just be ;

    A real life example can be:

    var j;
    for (j = i + 1; j < binstrN.length && binstrN[j] != 1; j++) {
    }
    let count = j - i;
    

    is same as

    var j;
    for (j = i + 1; j < binstrN.length && binstrN[j] != 1; j++);
    let count = j - i;
    

    Here we are trying to move j to next '1', while i was already at a '1' before it, hence count gives the distance between first two '1's in the string binary string binstrN

    0 讨论(0)
  • 2021-02-06 20:50

    use //pass like python's 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

    0 讨论(0)
  • 2021-02-06 20:51

    If you want to just use the pass operator in a ternary operator or just in an if statement in JS, you can do this:

    a === true && console.log('okay')
    

    You can use also use || operator but you should know that the || is the opposite of &&. Then if you want to use Pass in a function or a block in general as we do in Python like this:

    def Func(): pass
    

    In JS you should just leave the block empty as this:

     if(){ 
        console.log('ok')
        }else{}
    

    In the end, there are no braces in Python, so this is the main reason why we have a pass.

    0 讨论(0)
提交回复
热议问题