string.substr(start, length)start: The position where to start the extraction, index starting from 0. length: The number of characters to extract (optional). example
The above code would return "Script".Syntax
string.substring(start, end)start: The position where to start the extraction, index starting from 0. end: The position (up to, but not including) where to end the extraction (optional). example
The above code would return "Script"
substr() Vs. substring()The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to return. Moreover, substr() accepts a negative starting position as an offset from the end of the string. substring() does not.
- What is noscript tag?
- Difference between '=', '==' and '===' operators?
- What is Browser Object Model
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What's the Difference Between Class and Prototypal Inheritance?
- Event bubbling and Event Capturing in JavScript?
- What is the difference between .call() and .apply()?
- What is an immediately-invoked function expression?
- What Are RESTful (REpresentational State Transfer)Web Services?
- TypeError: document.getelementbyid(...) is null
- What's the difference between Null and Undefined?