
str.endsWith(substring) 메소드는 주어진 문자열의 끝부분이 주어진 substring과 일치하는지 확인합니다. substring이 없을 때, 메소드는 true를 반환하지 않습니다. 대신, undefined를 반환하지 않고 false를 반환합니다.
이러한 동작은 ECMA-262 5.1 specification의 15.3.4.9 section에 명시되어 있습니다. substring이 없을 때, 메소드는 false를 반환하는 것이 명시되어 있습니다.
이러한 동작은 JavaScript의 메소드 중 하나로, substring이 없을 때 false를 반환하는 것이 일반적인 동작입니다.
만약 substring이 없을 때 undefined를 반환하고 싶다면, 메소드를 직접 구현하여 substring이 없을 때 undefined를 반환하도록 할 수 있습니다.
예를 들어, 다음과 같은 메소드를 직접 구현할 수 있습니다.
#hostingforum.kr
javascript
String.prototype.endsWithCustom = function(substring) {
if (substring === undefined) {
return undefined;
}
return this.endsWith(substring);
}
이 메소드는 substring이 없을 때 undefined를 반환하도록 구현되어 있습니다.
2025-08-12 21:49