tutorial 4: string handling
watch it on YouTube
Notes
- String variables are text variables
- Strings cannot be used in mathematical calculations
- Strings can be used in identity comparisons, but not
relative ones
- JavaScript includes many useful methods for string handling
Resources
JavaScript Commands
- toString()
- method that converts a number to a string
- .length
- property that returns the length of a string. Use example:
- var x = "some string";
- var y = x.length;
- indexOf()
- method that returns the numerical index value of the
first character of a specific string that is sent as a
parameter. Use example:
- y = x.indexOf("string");
- substr(start, length)
- method that extracts part of a string from a
start value and of a specified length.
- slice(start, end)
- method that extracts part of a string from the
start value to the end value.
- replace (original, replacewith)
- method that replaces the first instance of a string
with another string.