var 의 쓰임새
2014.07.14 11:42
1024
0
https://eond.com/350190
object(HotopayModel)#805 (23) { ["error"]=> int(0) ["message"]=> string(7) "success" ["variables"]=> array(0) { } ["httpStatusCode"]=> int(200) ["module"]=> string(7) "hotopay" ["module_info"]=> NULL ["origin_module_info"]=> NULL ["module_config"]=> NULL ["module_path"]=> string(52) "/home/eond/web/eond.com/public_html/modules/hotopay/" ["xml_info"]=> NULL ["module_srl"]=> NULL ["mid"]=> NULL ["act"]=> NULL ["template_path"]=> NULL ["template_file"]=> NULL ["layout_path"]=> NULL ["layout_file"]=> NULL ["edited_layout_file"]=> NULL ["stop_proc"]=> bool(false) ["user"]=> object(Rhymix\Framework\Helpers\SessionHelper)#804 (20) { ["member_srl"]=> int(0) ["user_id"]=> NULL ["user_name"]=> NULL ["nick_name"]=> NULL ["email_address"]=> NULL ["phone_number"]=> NULL ["homepage"]=> NULL ["blog"]=> NULL ["birthday"]=> NULL ["denied"]=> NULL ["status"]=> NULL ["is_admin"]=> string(1) "N" ["is_site_admin"]=> NULL ["profile_image"]=> NULL ["image_name"]=> NULL ["image_mark"]=> NULL ["signature"]=> NULL ["description"]=> NULL ["group_list"]=> array(0) { } ["menu_list"]=> array(0) { } } ["request"]=> object(Rhymix\Framework\Request)#10 (13) { ["method"]=> string(3) "GET" ["compat_method"]=> string(3) "GET" ["url"]=> string(32) "javascript/350190/comment/464759" ["hostname"]=> string(8) "eond.com" ["domain"]=> NULL ["protocol"]=> string(5) "https" ["callback_function"]=> string(0) "" ["_route_status":protected]=> int(200) ["_route_options":protected]=> object(stdClass)#11 (5) { ["cache_control"]=> bool(true) ["check_csrf"]=> bool(true) ["is_forwarded"]=> bool(false) ["is_indexable"]=> bool(true) ["enable_session"]=> bool(true) } ["module"]=> string(5) "board" ["mid"]=> string(10) "javascript" ["act"]=> string(16) "dispBoardContent" ["args"]=> array(5) { ["page"]=> int(5) ["document_srl"]=> string(6) "350190" ["comment_srl"]=> string(6) "464759" ["mid"]=> string(10) "javascript" ["act"]=> string(16) "dispBoardContent" } } ["ajaxRequestMethod"]=> array(2) { [0]=> string(6) "XMLRPC" [1]=> string(4) "JSON" } ["gzhandler_enable"]=> bool(true) }

<html> 
<body> 
<script> 
var dan = 1; 
var count = 3; 
function test(){ 
   while( dan <= 9){ 
      var count = 1; 
      dan = dan + 1; 
   } 

test(); 
document.write(count); 
</script> 
</body> 
</html> 


var 의 있음 없음에 동작은 정상적으로 돌아갑니다.


하지만 자바스크립트에서는 var 를 써주느냐 안써주느냐에는 차이가 있습니다. javascript 함수를 배우셨다면 function 문을 이해하실 수 있으실텐데요 

그러면 count 값을 표시하는 document.write( count); 에서 화면에는 숫자 몇이 표시될까요?


function test 내의 var count = 1 의 var 를 제거하고도 테스트해보세요.


출처 : 네이버 지식인 

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040202&docId=200069125&qb=Y291bnQg7Iqk7YGs66a97Yq4&enc=utf8&section=kin&rank=3&search_sort=0&spq=1&pid=RJHUGF5Y7uossZBev8Rsssssst0-118916&sid=U75X3nJvLDIAAEheE-o

라이믹스는 이온디와 함께

닫기

마이페이지

로그인을 해주세요

네이버로 로그인