Resetting property value without assignment?

I’m studying this code from this guide and I don’t understand how the clearer() function works on line 223.

  clearer: function(){
      $("#display").text(0);
      this.state = states.START;
      this.op;
      this.disp;
      this.acc1;
      this.acc2;
},

If you’ve already pressed some buttons on the calculator and those variables have changed, wouldn’t you have to assign them with an empty string, like this.acc1 = "";? How does just the property declaration clear the value?

Thanks for any help!

It doesn’t. Just writing the property in a statement doesn’t do anything. Here’s a quick demo.

But it looks like there’s more going on in the calculator code such that there’s no need to clear those values.

2 Likes

It isn’t very nice code that you’re reading - there are much better ways to structure it, I think.

I’m guessing he forgot to clear those variables but it doesn’t matter because it doesn’t do anything until they’ve been over-written anyway (he got ‘lucky’) - he’s clearing the display text on the screen manually but not the underlying variable.

Made me feel better about my own shitty code, anyway :slight_smile:

1 Like

Yea you’re right. It’s look like even if he hit the clear button on his calculator, the old values would still be in acc1 and acc2 and would be reassigned when he pressed new numbers.

Thank you :slight_smile: !!!

I ran my own tests and thought maybe there was something I didn’t understand about the language…

Thank you for the example, that’s reassuring of my own knowledge :).