Is this a valid program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is this a valid program?

var a = 10; function a (name) { console.log(name); } Is this a valid program? Javascript

17th Nov 2017, 3:53 PM
Ajay Divvela
Ajay Divvela - avatar
6 Answers
+ 1
Your variable 'a' will probably conflict with your function name, so more than likely your program won't work as intended. However, technically, it's still a program even if it doesn't work right. var myVar = 10; function a(name) { alert(name); } a(myVar); ^That gets rid of naming conflict and allows it to function.
17th Nov 2017, 4:01 PM
AgentSmith
+ 2
You're welcome. Good luck with your learning!
17th Nov 2017, 4:13 PM
AgentSmith
+ 1
@Ajay In your version of the code, you never even call the function, so it'll do nothing. If you call the function, it'll conflict with your variable and again, do nothing. If you correct the naming conflict, and call the function, it'll print the result to the console for you. EXAMPLE:::: var myVar = 10; function a(name) { console.log(name); } a(myVar); OUTPUT::: 10
17th Nov 2017, 4:10 PM
AgentSmith
+ 1
Thanks!
17th Nov 2017, 4:11 PM
Ajay Divvela
Ajay Divvela - avatar
0
I want to know what the console.log(name) will do there.
17th Nov 2017, 4:09 PM
Ajay Divvela
Ajay Divvela - avatar
- 1
Run it in js and add alert(a) or what ever you want to test
17th Nov 2017, 3:58 PM
Ole113
Ole113 - avatar