简体   繁体   中英

how to reset javascript variable declared by keyword var?

I have an 'init' function in which i have few variables which i want to set as undefined/null on logout event.

var EmpCode;
function initChat(user, usertoken, ip){ 
  if(user!= null){
    EmpCode = user;
    var time_id = Date.now();
//some function calls.
}

function logout(){
//reset variable
}

i want to reset 'EmpCode' variable value on on logout function.

delete EmpCode; does not seems to work because it is defined by keyword var.

function logout(){
  //reset variable
  EmpCode = undefined; // or null
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM