codegurukool.com · Free coding tutorials & online compiler

Home › JavaScript Tutorial › JS strings

JS strings

Text and its methods.

Common methods: length, slice, toUpperCase, includes, replace, split, trim, padStart.

Example code

<pre id='o'></pre>
<script>
const s='  Hello World  '.trim();
o.textContent=[s.length,s.toUpperCase(),s.slice(0,5),s.includes('World'),s.replace('World','JS'),s.split(' ')].join('\n');
</script>

Run this code in the online editor

← JS loopsJS numbers →