Web Analytics Made Easy -
StatCounter Is indexOf a literal - CodingForum

Announcement

Collapse
No announcement yet.

Is indexOf a literal

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is indexOf a literal

    Hi,

    i am curious if indexOf is a literal or if it still need to check for uppercase chars.

    Code:
    indexOf("IAGREE") == -1)  //not found
    
    //is whatever is in the quotes a litteral - example js will see it as uppercase
    
    //or do i need to check it for uppercase using
    
    str === str.toUpperCase()
    thanks
    If a php file only has php code within it you do not need to use the closing php tag
    A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
    durangod is short for durango dave

  • #2
    Usually comparisons in JS are case-sensitive.

    But let's dive into the specification: ECMAScript 2020 section 21.1.3.8 String.prototype.indexOf
    (I'm assuming that you mean String.indexOf, not Array.indexOf)

    After a couple of definitions we see
    Return the smallest possible integer k not smaller than start such that k + searchLen is not greater than len, and for all nonnegative integers j less than searchLen, the code unit at index k + j within S is the same as the code unit at index j within searchStr; but if there is no such integer k, return the value -1.
    The important part here is
    the code unit at index k + j within S is the same as the code unit at index j within searchStr
    And since code units (or code points with regard to UTF) designate a specific character, we can conclude that the comparison must be case-sensitive.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

    Comment


    • #3
      Thanks, not sure i could have understood that without you... much appreciated... :0 ) I actually ended up doing it in two statments within the same function, one for the word and one for the UPPERCASE
      If a php file only has php code within it you do not need to use the closing php tag
      A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
      durangod is short for durango dave

      Comment


      • #4
        The JS specification is written for people that write JS implementations (browser engines) not for script creators. Hence the language is very technical, but for the same reason it is very exact.
        The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
        André Behrens, NY Times Software Developer

        Comment


        • #5
          Yeah im sure they have to be very very exact at their level...
          If a php file only has php code within it you do not need to use the closing php tag
          A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
          durangod is short for durango dave

          Comment

          Working...
          X