댓글 검색 목록

[javascript] 주어진 인수의 형식을 반환하는 JavaScript 함수를 작성하십시오.

페이지 정보

작성자 운영자 작성일 17-12-31 17:37 조회 1,305 댓글 0

코드 :

function detect_data_type(value)
{
var dtypes = [Function, RegExp, Number, String, Boolean, Object], x, len;
    
if (typeof value === "object" || typeof value === "function") 
    {
     for (x = 0, len = dtypes.length; x < len; x++) 
     {
            if (value instanceof dtypes[x])
            {
                return dtypes[x];
            }
      }
    }
    
    return typeof value;
}
console.log(detect_data_type(12));
console.log(detect_data_type('웹학교'));
console.log(detect_data_type(false));



결과 : 

number

string

boolean



댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.