Join the DZone community and get the full member experience.Join For Free
Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.
substring (ECMAScript 5.1 Specification Section 22.214.171.124) is the first logical choice to retrieve a part of the string. This
substring function can accept two numbers, the start and the end (exclusive) character position, respectively. In case the end value is smaller than the start, substring is smart enough to swap the values before doing the string extraction. An example of substring is illustrated in this code snippet:
var a = 'The Three Musketeers'; a.substring(4, 9); 'Three' a.substring(9, 4); 'Three'
substr (Section B.2.3). However, the parameters for
substr are the start character position and the numbers of characters to be extracted, respectively. This is shown in the following fragment:
var b = 'The Three Musketeers'; b.substr(4, 9); 'Three Mus' b.substr(9, 4); ' Mus'
Prevention is the best cure. Be advised of your function name!
Published at DZone with permission of Ariya Hidayat , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.