Hi Friends iam new to javascript Functions so plase help me to understand this code | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 5

Hi Friends iam new to javascript Functions so plase help me to understand this code

function name(yourname){ x=10; var x; document.write(x); } document.write(name("imran")); its result 10 and undefined, when I remove this document.write() from name() its result 10, can I return yourname parameter or what I do, I have some problem with the return property.so please help me.

8th Oct 2019, 3:00 PM
Ekram Mallick
Ekram Mallick - avatar
1 Antwort
+ 4
If you want to return any value from function then you can right like this. function name(yourname) { return yourname; } If you want both means print other value and return name then you can write like this function name(yourname) { var x = 10; document.write(x); return yourname; } It will print the value of x as well as returns name also.
8th Oct 2019, 3:07 PM
A͢J
A͢J - avatar