JS - Day 4
/// String: string is the collection of characters.
// string is written in single or double quote or back quote
// Example of string
let a = 'Ram' // written in single quote
let b = "Sham" // written in double quote
let c = `Laxman` // written in back quote
let d = '1234' // numbers written in quote is also a string
//* In Javascript everything is an object so every object have some properties and methods
// example: our body is an object it has properties like weight, height, colour etc.
// and the methods are walk, talk, sleep, sit etc. and performing that methods is action and when we get
// something because of that then its is a return. like we do exercise and we get good muscles as a return.
// like the above said example every object in JavaScript has properties & methods and method includes action and return
//* In string every character has a stored index number
// Example of stored index number in string :
let e = 'Sita' // here stored index value of S is 0, i is 1, t is 2, a is 3
// if we type console.log(e[0]) then it will return S
console.log(e[0])
// if we type console.log(e[1]) ir will return i
console.log(e[1])
let z = 'Rameshwar'
console.log(z[6]) // this will return character with index value 6 i.e. w
//* string has length property
let f = e.length // we have stored length code in f variable for getting length of string named 'e'
console.log(f)
// or we can directly just see the length in console without storing length code in other variable like we
// have stored e.length code in f variable // we can type console.log(e.length) but it will just show us result
// but storing the code in other variable is good so that we can use it whenever we need
console.log(e.length)
let sir = 'Deshpande'
let g = sir.length
console.log(g) // this will return length of string named 'sir' in number type (i.e. in number) // return: 9
let x = z.length
console.log(x) // this will return length of string named 'z' in number type (i.e. in number) // return: 9
//* methods of string
//1) toUpperCase()
let district = 'nagpur'
let p = district.toUpperCase()
console.log(p)
//2) toLowerCase()
let state = 'MAHARASHTRA'
let q = state.toLowerCase()
console.log(q)
//3) indexOf()
let r = state.indexOf('T')
console.log(r)
//4) includes()
let t = state.includes('T')
console.log(t)
Comments
Post a Comment