Why does the clock fire when the value of oldvalue is equal to newvalue?

I have:

   $scope.$watch('option.sSubject', function (newValue, oldValue) {
                    if (newValue !== oldValue) {

and

console.log(newValue)
1
undefined
console.log(oldValue)
1
undefined

Can someone explain why the watch works when there seems to be no change in value. Please note that this is when I just open the page.

+3
source share
1 answer

A quote from the API documentation in $ scope. $ apply ():

, , fn ( $evalAsync) . , , watchExpression . fn, newVal oldVal. (===), - .

+8

All Articles