Q:

ReferenceError: var is not defined

I have an angularjs code in which a variable dataKey is given a value in watcher. When I log the value in console, it gets displayed (for ex. 4) but in the following statement, it gives the error: ReferenceError: datakey is not defined. How is that possible?
Here is the code snippet.
myApp.directive('circlepackingChart', function($window) {
    return {
        restrict: 'EA',

        link: function(scope, elem, attrs) {
            var dataFile = scope.dataFile;
            var dataKey = attrs.expKey|| false;
            var d3 = $window.d3;
            var div = elem[0];
            var width = div.offsetWidth;
            var height = width / 2;

            scope.$watch(function() {
                return attrs.expKey;
            }, function(value) {

                dataKey = value || false;

                console.log(datakey);

                if (datakey) {
                    drawCirclePacking();
                }

            });
            drawCirclePacking = function(){
                /*some code*/
            }
        }
    }
});

A:

JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
datakey IS not defined, because you defined dataKey

