In Javascript, is there a technique where I can execute code after a return?

Posted by Christopher Altman on Stack Overflow See other posts from Stack Overflow or by Christopher Altman
Published on 2011-02-01T15:18:57Z Indexed on 2011/02/01 15:25 UTC
Read the original article Hit count: 272

Filed under:

Is there a technique where I can execute code after a return? I want to return a value then reset the value without introducing a temporary variable.

My current code is:

function(a){
  var b;

  if(b){
    var temp = b; //I want to avoid this step
    b = false;
    return temp;
  }else{
    b = a;
    return false;
  };
};

I want to avoid the temp var. Is that possible?

var b holds a value between function calls because it is a memoization styled function.

© Stack Overflow or respective owner

Related posts about JavaScript