+ 1
Is this a valid program?
var a = 10; function a (name) { console.log(name); } Is this a valid program? Javascript
6 Respostas
+ 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.
+ 2
You're welcome. Good luck with your learning!
+ 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
+ 1
Thanks!
0
I want to know what the console.log(name) will do there.
- 1
Run it in js and add alert(a) or what ever you want to test