Some sample JavaScript code snippets for:
- Declaring string variables in JavaScript and using typeof to test that a variable contains a string.
- Concatenating strings with the + operator and spliting them with the slice() method.
- Using index position and the .length property to work with string characters.
- Removing whitespace with trim() and changing character case with toUpperCase() and toLowerCase().
- Using various methods to query a string by index position and character(s).
- Searching and replacing string characters.
Instructions for use
- the web page containing the JavaScript code.
- Open the page in Brave or other, lesser web browsers.
- View the JavaScript output by pressing the following keys and selecting the Console tab:
- Ctrl + Shift + i (Windows)
- ⌘ Command + Shift + i (Mac).
- Open the web page in VS Code, VS Code Online or Sublime Text. All are good choices.
- Play around with the JavaScript code. Change things and see what happens.
✅ That’s it.