"함수 is defined()"의 두 판 사이의 차이

잔글 (Jmnote 사용자가 다언어 is defined() 문서를 함수 is defined() 문서로 옮겼습니다)

2016년 4월 10일 (일) 02:30 판


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 Ruby

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

5 같이 보기

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