0

undefined or null

the var a in this program is not defined. so it is printing undefined. but the tutorial guy is getting null value as result but i am getting undefined. can anyone tell me why? https://code.sololearn.com/WFVPAcuaTrQK/?ref=app

23rd Aug 2020, 8:22 AM
Mr. 12
Mr. 12 - avatar
9 Respuestas
+ 3
Because your variable doesn't have value. So it is showing undefined.
23rd Aug 2020, 8:49 AM
TOLUENE
TOLUENE - avatar
+ 2
Vanilla JS always assigns unassigned variables (without an initial value) to undefined, undefined being an primitive data type. Null is the *intentional* absence of an object. I am really confused, I don't know why he is getting null. Maybe modified JS, interpreter settings (if there are any), I really don't know. I couldn't either found anything on the internet.
23rd Aug 2020, 7:58 PM
🈂️Toma
🈂️Toma - avatar
+ 1
Are you sure the source codes were exactly the same? you're talking about the tutorial guy Youtube channel right?
23rd Aug 2020, 8:54 AM
Ipang
+ 1
yes Ipang javascript tutorial in freecodecamp youtube channel
23rd Aug 2020, 9:17 AM
Mr. 12
Mr. 12 - avatar
+ 1
Ipang he is getting null as output
23rd Aug 2020, 9:24 AM
Mr. 12
Mr. 12 - avatar
0
I don't know about other languages but in javascript undefined is result if you define a variables but not assign its value. Null is result if you assign null value to variable .
23rd Aug 2020, 9:24 AM
Divya Mohan
Divya Mohan - avatar
0
Share the link of video
23rd Aug 2020, 9:26 AM
Divya Mohan
Divya Mohan - avatar
23rd Aug 2020, 9:28 AM
Mr. 12
Mr. 12 - avatar
0
That's a case among UB (Undefined Behavior) ones. When a value is set without, initialization or without assigning it, so using this last one will be an ill-formed situation.
24th Aug 2020, 11:14 PM
Med Arezki
Med Arezki - avatar