6. console.log is not a function? Wat?


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/1/2?curriculum_id=506324b3a7dffd00020bf661


So, weird thing happening with the code here. I've been looking through the forums, through other references, can't figure out what's going on. This is the code below for 7.6, Solo Flight. I'm getting a constant console error of

TypeError: console.log is not a function.

What's the cause for this? Never had issues with it before in other instances - is it just a syntax issue or something?


var initialcondition = true;

var soloLoop = function(){
    while (initialcondition){
        console.log("Looped once!");
        initialcondition = false;
    }
};

soloLoop();


#2

try to refresh/reload your browser


#3

Copy your code and reload the page so JavaScript gets reset. Something must have overwritten console.log().

An example of this happening would be the result of writing something like,

console.log = "Looped once!";

That effectively overwrites the method of the console object.

var bob = {};
bob.log = function(x) {
    console.log(x);
};

bob.log(bob.log.toString());
/*
function (x) {
    console.log(x);
}
*/
bob.log = "Logging it!";

bob.log(bob.log.toString());

TypeError: bob.log is not a function


#4

That worked. Thanks guys!


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.