Today I Learned - Rocky Kev

TIL the Capitalize String shortcut

POSTED ON:

TAGS:

I use this a bunch. But i also always forget it.

Unlike other popular programming languages like Python, C#, and PHP JavaScript doesn’t have a function that allows you to capitalize a string. However, it’s quite a basic function that gets used a lot. You can put in a word or a complete sentence to this function, as long as it’s a string.

const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);

REF:
https://javascript.plainenglish.io/15-helpful-javascript-one-liners-946e1d1a1653


Related TILs

Tagged:

TIL why you should always use textContent

Today I learned the difference between 'Node.textContent'. It handles all elements, even hidden ones. It also prevents XSS attacks since it strips tags.

TIL prepend

When you're creating new elements in Javascript, you want to attach the new element to something that exists in the DOM already. You do that with append, and prepend.

TIL the simulating a Pipe function

It’s a pipe function that allows you to chain multiple operations together by taking a series of functions as arguments and applying them in a specific order to the input.