Calling str Methods by Their JavaScript Names

With .slice() cutting the commit subject, the rest of ticket_branch.py leans on everyday string operations, such as strip() for the title, lower() for the branch, and in for the currency check. JavaScript has the same toolkit under longer camelCase names, and only the currency check changes shape.

Look Up the New Names

Each method you need has a JavaScript name. On plain text like these headers, and with a single string as the argument rather than Python’s tuple of prefixes, each behaves as its Python twin does:

Python JavaScript
strip(), lstrip(), rstrip() .trim(), .trimStart(), .trimEnd()
lower(), upper() .toLowerCase(), .toUpperCase()
startswith(p), endswith(s) .startsWith(p), .endsWith(s)
find(sub) .indexOf(sub)
sub in text text.includes(sub)

As in Python, strings can’t change, so .trim() and .toLowerCase() return a new string, and the calls chain left to right, as raw_title.strip().lower() does. Here’s the title after the helper splits the header, with its leading space:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.