함수 is defined()

(다언어 is defined()에서 넘어옴)


1 Bash[ | ]

a=hello
if [ -n "$a" ]; then
	echo "Yes"
else
	echo "No"
fi
# Yes
if [ -n "$b" ]; then
	echo "Yes"
else
	echo "No"
fi
# No

2 JavaScript[ | ]

var a = 1;
console.log( ( typeof a != 'undefined' ) ); // true
console.log( ( typeof b != 'undefined' ) ); // false

3 PHP[ | ]

$a = 1;
var_dump( isset($a) );
# bool(true)
var_dump( isset($b) );
# bool(false)

4 Python[ | ]

a = 1
print( 'a' in vars() )
# True
print( 'b' in vars() )
# False
a = 1
print( 'a' in globals() )
# True
print( 'b' in globals() )
# False
a = 1
try:
    a
    print( True )
except NameError:
    print( False )
# True
try:
    b
    print( True )
except NameError:
    print( False )
# False

5 Ruby[ | ]

a = 1
puts defined? a
# local-variable
puts defined? b
# nil

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}