Before going here to ask a question, I honestly googled for an hour, but could not find the answers, although in some links there was something similar. The question is what does JS mean zero in the following construction:

var n = (0, window.unescape)("somestring"); 

I would be grateful for an answer or a link where you can read.

    1 answer 1

    in this case, it does not mean anything and anything could have happened instead. We need it here to trigger the operator comma .

    With this application of the comma operator, you can get a link to the method detached from the current context and when you call it, the global context will be used. In this case, window .

    That is, the record in the question is equivalent to the following

     var unescape = window.unescape; var n = unescape("something"); 

    Given that in this case, the function will always be called in a global context, there is no point in doing this and you can get by with the usual call

     var n = window.unescape("somestring"); 

    Example when it makes sense

     var a = { func: function() { console.log('eval context is window: ', (0, eval)("this") === window); console.log('eval context is current object: ', eval("this") === a); }, func1: function() { console.log('context: ', this.toString()); } } a.func(); (1, a.func1)(); (a.func1)(); 

    • one
      Why does the comma change context? Definitely a trap of JS architecture. - user207618
    • I would like to add a link to the detailed description of this operator, but I also learned something new for myself =) - Konstantin Basharkevich
    • one
      @Other, the context changes not a comma, but its use. in essence, this is an operator that returns the last operand, in this case it is a reference to a method, that is, we took this reference and returned it and then immediately called it. - Grundy
    • one
      Ndaa, funny cameraman operator comma - Konstantin Basharkevich
    • four
      Read the link respected @ Konstantin Запятая позволяет перечислять выражения, разделяя их запятой ','. Каждое из них – вычисляется и отбрасывается, за исключением последнего, которое возвращается. [ Запятая позволяет перечислять выражения, разделяя их запятой ','. Каждое из них – вычисляется и отбрасывается, за исключением последнего, которое возвращается. Запятая позволяет перечислять выражения, разделяя их запятой ','. Каждое из них – вычисляется и отбрасывается, за исключением последнего, которое возвращается. ] and understood what and why, thank you for your clarification on the topic. - user207618