Javascript strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • debby
    New Member
    • May 2010
    • 1

    Javascript strings

    what are the values of thirdVar, fourthVar and fifthVar after these lines of javascript have been executed.

    Code:
    var firstVar = 'Joseph' ;
    var secondVar = ' Locke' ;
    var thirdVar = firstVar.charAt (0) + '. ' + secondVar;
    var fourthVar = thirdVar.length;
    var = 'The last character is' + thirdVar.charAt(fourthVar) + ' ! ' ;
    Last edited by Dormilich; May 29 '10, 11:55 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    isn’t that obvious? just do mentally, what the JavaScript engine does, it’s not complicated.

    PS. aint that Ashley Lynx?

    Comment

    • RamananKalirajan
      Contributor
      • Mar 2008
      • 608

      #3
      It will be empty space or null or undefined logically speaking. Because thirdVar.length will have 8. But the thirdVar is a string and it will be stored like [0] -> J, [1] -> ., [2] -> a space, [3] -> L, [4] -> o, [5] -> c, [6] -> k, [7] -> e. This is how the value will be stored. When u try to fetch charAt[8] it will return a empty value, null or exception.

      Thanks and Regards
      Ramanan Kalirajan

      Comment

      Working...