Why dose it give me [object object] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why dose it give me [object object]

function e(p) { console.log(p); p = 5; console.log(p); } https://code.sololearn.com/Wd0SWquGDNJR/?ref=app

15th Jun 2022, 12:19 PM
Varin
Varin - avatar
6 Answers
+ 1
Your function doesn't output anything as it is never called. Can you please check what exactly you did when you got that output?
15th Jun 2022, 12:46 PM
Lisa
Lisa - avatar
+ 1
Anthony Johnson There is no need to declare p because p is a parameter of the function.
16th Jun 2022, 11:56 AM
ODLNT
ODLNT - avatar
18th Jun 2022, 9:40 PM
Varin
Varin - avatar
0
The reason is because you tried to log the value of p before its value was declared.
16th Jun 2022, 12:08 AM
Anthony Johnson
Anthony Johnson - avatar
0
ODLNT Yes if there is a parameter given, but declaring p = 5 after passing in the value of p is pointless. A beter practice would be. function e(p) { this.p = p; console.log(this.p); console.log(this.p + 5); } e(5); //first output 5 //second output 10
18th Jun 2022, 8:52 PM
Anthony Johnson
Anthony Johnson - avatar