+ 1

Why does this code prints not only the argument passed to the function but also an undefined type.

https://code.sololearn.com/W5PSTwvWlQd5/?ref=app

25th Aug 2022, 9:29 AM
Dhanraj Tamang
Dhanraj Tamang - avatar
14 Answers
+ 1
I'm sorry for misunderstanding but what I was saying is, when you use "console.log" it mean that you are printing something on console. //Declaration of a function to print a variable name on console function sayName (name) { console.log(name) } The when you write console.log(sayName('e')) It means you are parsing a value "e" to a function so the statement starts with a function call. Then on console.log() there is no variable that's why it prints "undefined" This means when you call console.log(sayName ('e')) console.log(sayName ('f')) It will print e undefined f undefined
25th Aug 2022, 2:24 PM
Elia N Lameck
Elia N Lameck - avatar
+ 4
Yaroslav Vernigora thanks a lot for the explanation.
25th Aug 2022, 10:35 AM
Dhanraj Tamang
Dhanraj Tamang - avatar
+ 4
Ok. Thank you for being so nice. I'll refer to it on my web development journey.
25th Aug 2022, 10:41 AM
Dhanraj Tamang
Dhanraj Tamang - avatar
+ 3
Hi! because console.log after execution cannot return anything back. function sayName(name){ console.log(name) } sayName('e')
25th Aug 2022, 9:34 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
The “undefined” value The special value undefined also stands apart. It makes a type of its own, just like null. The meaning of undefined is “value is not assigned”. If a variable is declared, but not assigned, then its value is undefined: let age; alert(age); // shows "undefined" Technically, it is possible to explicitly assign undefined to a variable: let age = 100; // change the value to undefined age = undefined; alert(age); // "undefined" 
But we don’t recommend doing that. Normally, one uses null to assign an “empty” or “unknown” value to a variable, while undefined is reserved as a default initial value for unassigned things.
25th Aug 2022, 9:55 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
I'm advise you this site: https://javascript.info/
25th Aug 2022, 10:40 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
you're welcome
25th Aug 2022, 10:44 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Jessica Cristal Can you help me here please.
25th Aug 2022, 9:32 AM
Dhanraj Tamang
Dhanraj Tamang - avatar
+ 1
Yaroslav Vernigora thanks for checking out my code but i wanted to know why does my code prints not only 'e' but also 'undefined'
25th Aug 2022, 9:37 AM
Dhanraj Tamang
Dhanraj Tamang - avatar
+ 1
I wrote to you about it above. review again carefully my message.
25th Aug 2022, 9:52 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Manoti (Challenge Accepted) first of all you are wrong for assuming what i wanted to do(because i was just playing around to learn) And you also didn't answer why my code( console.log(sayName('e')) prints undefined.
25th Aug 2022, 12:55 PM
Dhanraj Tamang
Dhanraj Tamang - avatar
0
You declared a function with it's statement to print the name. Also when calling the function you are also using a statement to print your function. You should just call the function function sayName(name){ console.log(name) } sayName("e")
25th Aug 2022, 12:18 PM
Elia N Lameck
Elia N Lameck - avatar
- 2
Mina Adel
26th Aug 2022, 10:55 AM
Mina Adel
Mina Adel - avatar
- 2
Hello
27th Aug 2022, 3:03 AM
Prince Gautam
Prince Gautam - avatar