+ 3

guys whats the difference between this?

var a=console.log a("hii i am aniket") // or console.log("hii i am aniket")

13th Sep 2021, 3:03 AM
Aniket Ganguly
17 Réponses
+ 6
It's called caching, it's a technique to store used data, so it can be accessed easily. You might want to rename it to “log” since it makes more sense that way const log = console.log;
13th Sep 2021, 3:06 AM
Tim
Tim - avatar
+ 3
Aniket Ganguly That's to avoid writing console.log everytime. There is no difference. We just have stored console.log to a variable. So using that variable we can print anything. That variable will work like a function. It is like how you define function like: var func = function () { } Now here func will behave as a function.
13th Sep 2021, 4:43 AM
A͢J
A͢J - avatar
+ 1
Aniket Ganguly It is not possible to tell all functions so try to find self on Google. Go here and see https://developer.mozilla.org/en-US/docs/Web/JavaScript
13th Sep 2021, 6:49 AM
A͢J
A͢J - avatar
+ 1
I think these answers are misleading. log is a method. it means that log is a function blongs to console object. some methods are not dependent on their objects. such as methods that don't use this keyword. we can use them as function var mylog = console.log; but see this: var obj={ data:7, method:function() { console.log(this.a); } } a. method() ;//prints 7 but if you try to use my method: var meth=obj.method; meth(); //in strict mode: Cannot read properties of undefined. because this is undefined in that function //in normal mode: prints undefined because this refers to window object. and window.data is undefined. log method and also pop in Array prototype are defined in native code. log isn't dependent on console object but pop is dependent on the array data. there is a useful method in function prototype know as bind method that replaces this with its argument and returns the new function. in native method it acts like a rename var a=[1, 2] var pop=a.pop.bind(a); pop() ;//know a is [1]
14th Sep 2021, 8:04 PM
Mehran
Mehran - avatar
0
How I use this data using log()??
13th Sep 2021, 3:41 AM
Aniket Ganguly
0
Aniket Ganguly log is now referencing console.log, just use it the way you would use console.log
13th Sep 2021, 3:43 AM
Tim
Tim - avatar
0
Nick then what's the difference between this??explain me plzz
13th Sep 2021, 3:44 AM
Aniket Ganguly
0
HrCoder wht?
13th Sep 2021, 3:47 AM
Aniket Ganguly
0
I need difference between two of codes
13th Sep 2021, 4:00 AM
Aniket Ganguly
0
Okay thnx
13th Sep 2021, 4:45 AM
Aniket Ganguly
0
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ then that's why I got error this code ??? var a=[1,2,3,4] var pop1=a.pop console.log(pop1())
13th Sep 2021, 5:00 AM
Aniket Ganguly
0
Aniket Ganguly console.log is a global function but pop() is not so you can't do like that.
13th Sep 2021, 5:08 AM
A͢J
A͢J - avatar
0
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ nice explanation thank you
13th Sep 2021, 6:29 AM
Aniket Ganguly
0
But can you plzz tell me all function ??? A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟
13th Sep 2021, 6:32 AM
Aniket Ganguly
0
There is a far more different
14th Sep 2021, 1:44 PM
Odonghanro Faith
Odonghanro Faith - avatar
0
I am not sure of that
14th Sep 2021, 3:29 PM
Odonghanro Faith
Odonghanro Faith - avatar