Undefined values: Difference between revisions

Content added Content deleted
(JavaScript)
No edit summary
Line 17:
 
then if you make the mistake of writing your program such that it at some point requires the value of <code>resurrect 0</code>, you'll get the error message "I'm out of orange smoke!".
 
=={{header|J}}==
J does not have a concept of an "undefined value" as such, but J does allow treatment of undefined names. The verb <code>nc</code> finds the (syntactic) class of a name. This result is negative 1 for names which have not been defined.
 
<lang J>
foo=: 3
nc;:'foo bar'
0 _1</lang>
 
From this we can infer that foo has a definition (and its definition is a noun), and bar does not have a definition.
 
This task also asked that we ''identify and exercise .. mechanisms for ... manipulating a variable's value's status as being undefined''. So: a name can be made to be undefined using the verb <code>erase</code>. The undefined status can be removed by assigning a value to the name.
 
<lang J>
erase;:'foo bar'
1 1
nc;:'foo bar'
_1 _1
bar=:99
nc;:'foo bar'
_1 0</lang>
 
=={{header|JavaScript}}==