Web Development
JavaScript
• To declare variable in javascript use:
1) var
Ex: var x=5;
2) let
Ex: let x=5;
3) const
Ex: const y=7;
JavaScript String Methods
• String methods help you to work with strings.
1) The length property returns the length of a string.
• To extract part of string use slice(), substring(), substr() functions.
JavaScript String Methods
2) slice(start, end): extracts a part of a string and returns the
extracted part in a new string.
• This example slices out a portion of a string from position 7 to
position 12 (13-1) and the output will be “Banana”.
JavaScript String Methods
3) substring(start, end): is similar to slice() and the difference is that
substring() cannot accept negative indexes.
• This example substring a portion of a string from position 7 to
position 12 (13-1) and the output will be “Banana”.
JavaScript String Methods
4) substr(start, length): is similar to slice() and the difference is that
the second parameter specifies the length of the extracted part.
• This example will print from position 7 to and count 6 characters
after it and the output will be “Banana”.
JavaScript String Methods
• Replacing String content:
5) replace() method : replaces a specified value with another value in
a string.
• This example will replace “Microsoft” with “W3schools”
JavaScript String Methods
• To convert string to UpperCase():
6) toUpperCase() method: will be used to convert string from
lower to upper case.
JavaScript String Methods
• To convert string to lower case():
7) toLowerCase() method: will be used to convert string from
Upper to lower case.
JavaScript String Methods
8) concat() method : joins two or more strings
JavaScript String Methods
9) trim() method : used to remove white spaces from both
sides of a string.
JavaScript String Methods
10) indexof() method : return index of
(position) of the first occurrence of specified
text in string.
•The result of this code will be 7.
JavaScript String Methods
11) lastindexof() method : return index of (position) of the last
occurrence of specified text in string.
• The result of this code will be 21.

Web Development_Sec6_Java secriptvvvvv.pdf

  • 1.
  • 2.
    JavaScript • To declarevariable in javascript use: 1) var Ex: var x=5; 2) let Ex: let x=5; 3) const Ex: const y=7;
  • 3.
    JavaScript String Methods •String methods help you to work with strings. 1) The length property returns the length of a string. • To extract part of string use slice(), substring(), substr() functions.
  • 4.
    JavaScript String Methods 2)slice(start, end): extracts a part of a string and returns the extracted part in a new string. • This example slices out a portion of a string from position 7 to position 12 (13-1) and the output will be “Banana”.
  • 5.
    JavaScript String Methods 3)substring(start, end): is similar to slice() and the difference is that substring() cannot accept negative indexes. • This example substring a portion of a string from position 7 to position 12 (13-1) and the output will be “Banana”.
  • 6.
    JavaScript String Methods 4)substr(start, length): is similar to slice() and the difference is that the second parameter specifies the length of the extracted part. • This example will print from position 7 to and count 6 characters after it and the output will be “Banana”.
  • 7.
    JavaScript String Methods •Replacing String content: 5) replace() method : replaces a specified value with another value in a string. • This example will replace “Microsoft” with “W3schools”
  • 8.
    JavaScript String Methods •To convert string to UpperCase(): 6) toUpperCase() method: will be used to convert string from lower to upper case.
  • 9.
    JavaScript String Methods •To convert string to lower case(): 7) toLowerCase() method: will be used to convert string from Upper to lower case.
  • 10.
    JavaScript String Methods 8)concat() method : joins two or more strings
  • 11.
    JavaScript String Methods 9)trim() method : used to remove white spaces from both sides of a string.
  • 12.
    JavaScript String Methods 10)indexof() method : return index of (position) of the first occurrence of specified text in string. •The result of this code will be 7.
  • 13.
    JavaScript String Methods 11)lastindexof() method : return index of (position) of the last occurrence of specified text in string. • The result of this code will be 21.