Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Foundations Strings Methods: Part 1

is it possible to turn console.log() into a variable or Function?

is it possible to turn console.log() into a variable or Function. that could be called on a shorter name like logIt ?

so far all my attempts have failed.

4 Answers

I did like this and it worked

<script>
   function logit(value){
      console.log(value);
   }
   logit("something");
</script>

Tell me if it works with you

Yes Dustin It worked perfect thanks a million.

You are welcome bro :)

I am not sure if this is what you want to achieve, but you may check this out.

Put this at the top of the file: var console = {}; console.log = function(){}; For some browsers and minifiers, you may need to apply this onto the window object. window.console = console;

Source: http://stackoverflow.com/questions/7042611/override-console-log-for-production

James Barnett
James Barnett
39,199 Points

Sure it is, you can even get console.log output to your screen, useful for using codepen while learning JS.

demo: http://codepen.io/jamesbarnett/pen/fwLpc

Thanks Every one! All of your guy's advice worked out very well. Now I am able to simplify a lot of of this code. my original code I was building was really close to Dustin's answer but no cigar.

function logit (inFo) {
logit  = console.log(inFo);
} 

thanks again guys !