0

I am new to javascript so my terminologies might be wrong. Since functions are just variables in javascript, why does the Chrome console complain when I do

var f = console.log  

and apply

f(123)  

The error log is the following.

Uncaught TypeError: Illegal invocation  
    at <anonymous>:2:1  
    at Object.InjectedScript._evaluateOn (<anonymous>:905:140)  
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)  
    at Object.InjectedScript.evaluate (<anonymous>:694:21)  
Barmar
  • 741,623
  • 53
  • 500
  • 612
hch
  • 6,030
  • 8
  • 20
  • 24
  • Format your questions nicely when you ask. Use capital letters to start a sentence. It doesn't matter if you are new to whatever your question is about. You are expected to ask decent questions - you are not new to asking questions are you? – JK. Aug 25 '15 at 04:29

1 Answers1

0

Works here: http://jsfiddle.net/8pL5Lgd2/

var f = console.log;
f("!23");
Mohammad Areeb Siddiqui
  • 9,795
  • 14
  • 71
  • 113
  • Saying that it works isn't an answer, since you haven't told him what to do to fix his problem. I believe this is browser-dependent. – Barmar Aug 25 '15 at 04:36