Javascript 3 – Use console to debug or die

Using alert() to debug really sucks. I always have to pray for my inserted alert to come up and it often doesn’t and I have no idea why or I kill my browser by never ending loop with alerts I can’t stop or I would get this error Object object that basically says “Just Give It Up!”.

Well, alert time is over. I was told to use a console.log(). Suddenly the JS world seems a bit nicer.

I prefer the Google Chrome console. You can activate it by hitting F12.

Example 1 – feeling much better already πŸ˜‰

[code lang=”js”]

var test = ‘Defined’;

var test2;



Example 2Β  – logging an object

[code lang=”js”]

var myObject = {};

myObject.color = "blue";
myObject.width = 345;
myObject.height = 150; = function() {
//method show


/* When you expand the logged "Object" you can see everything that belongs to it,
its properties and methods. Simple, right?


Example 3 – Testing functionality from console

[code lang=”js”]

// This is my function checking if a number is odd or even

function myIsOdd(x) {
if((x % 2) == 0) {
return false;
} else {
return true;

// you can quickly test the functionality from the console


If you are brave enough like me do this

[code lang=”js”]

// Whoaaaaaa!

Break. πŸ˜‰

var myObject = {};myObject.color = “blue”;
myObject.width = 345;
myObject.height = 150;


One Reply to “Javascript 3 – Use console to debug or die”

Leave a Reply

Your email address will not be published. Required fields are marked *