encodeURI vs encodeURIComponent

이동규 (Justin)·2021년 4월 23일

What's the difference?

encodeURI는 도메인과 URI scheme (ex. http)만을 인코딩하는 반면, encodeURIComponent는 전달된 URI String의 전체 부분을 인코딩 한다.

따라서 encodeURI는 완성되어 있는 URI 전체를 전달하여 인코딩할 때 적합하고, encodeURIComponent는 쿼리스트링 등 URI의 부분을 인코딩하여 기존 URI에 이어붙일 때 적합하게 사용될 수 있겠다. ("component" !!)

Example

encodeURIComponent("http://xyz.com/?a=12&b=55");

// "http%3A%2F%2Fxyz.com%2F%3Fa%3D12%26b%3D55"

encodeURI("http://xyz.com/?a=12&b=55");

// "http://xyz.com/?a=12&b=55"
profile
Visual Programming is in Progress..

0개의 댓글