Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String()과 .toString() 의 차이 #43

Open
mdgarden opened this issue Oct 4, 2022 · 1 comment
Open

String()과 .toString() 의 차이 #43

mdgarden opened this issue Oct 4, 2022 · 1 comment

Comments

@mdgarden
Copy link
Owner

mdgarden commented Oct 4, 2022

https://zenn.dev/doxper/articles/66b91dc8321802
프로그래머스에서

function solution(n)
{
    let answer = 0;
    const str = String(n); // 여기
    
    for (var i = 0; i < str.length; i++) {
        answer += parseInt(str[i]);
    }
    
    return answer;
}

이건 되는데

function solution(n)
{
    let answer = 0;
    const str = n.toString(); // 여기
    
    for (var i = 0; i < str.length; i++) {
        answer += parseInt(str[i]);
    }
    
    return answer;
}

이건 안되는 이유는 뭐임

@mdgarden
Copy link
Owner Author

mdgarden commented Oct 4, 2022

parseInt와 Number()의 차이도

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant