3. Short term memory


While the code is working properly, I'm not sure what is the role "this.add" plays in the scan method. Could someone please help explain to me why I can't just put a flat number but instead I need to put this.add?

var cashRegister = {
    total: 0,
    add: function(itemCost){
     this.total += itemCost  
    scan: function (item) {
        switch (item) { 
        case "eggs": 

        return true;


The methods have a context, cashRegister, referenced internally as this.

Notice that we call cashRegister.scan() from the outside, but this.add() from inside the object. This is known as execution context. Inside a method, local properties are referred as this.property. For example, this.total.

Is this starting to make sense?