I've run in to a situation that can't really explain how is this even possible.
I made a plunker for a demo.
THE CODE:
angular.module('test', []).controller('TestController', function($scope) {
/*
DEFAULT CONST VARIABLE
*/
const _DEFAULT = {
items: [],
name: 'Test',
selected: null
};
/*
TEST_CASE SCOPE VARIABLE
*/
$scope.test_case = _DEFAULT;
console.log('ON INIT DEFAULT: ', _DEFAULT);
/*
FUNCTION
*/
$scope.clicked = () => {
// SET TEST_CASE.SELECTED = 1
$scope.test_case.selected = 1;
// SHOW UPDATED TEST_CASE AND _DEFAULT VARIABLE
console.log($scope.test_case, _DEFAULT);
};
});
When button is clicked (check demo) we change data only in $scope.test_case
so HOW is it possible that const variable _DEFAULT
has the same data as $scope.test_case
when _DEFAULT
has never been touched or changed?
That should be impossible or am I missing something?