When you added the code after the $scope.test function, it has () . Therefore, because of this, the test function is considered as self , executing the function ,
As @estus already said, you can avoid this problem by ending your functional code on ; .
code
$scope.test = function() { console.log('Weird behaviour!') }(function() {} ())
source share