+ 3
guys whats the difference between this?
var a=console.log a("hii i am aniket") // or console.log("hii i am aniket")
17 Respuestas
+ 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;
+ 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.
+ 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
+ 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]
0
How I use this data using log()??
0
Aniket Ganguly
log is now referencing console.log, just use it the way you would use console.log
0
Nick then what's the difference between this??explain me plzz
0
HrCoder wht?
0
I need difference between two of codes
0
Okay thnx
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())
0
Aniket Ganguly
console.log is a global function but pop() is not so you can't do like that.
0
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ nice explanation thank you
0
But can you plzz tell me all function ??? A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟
0
There is a far more different
0
I am not sure of that