OneCompiler

JavaScript string basics

130

## /string is a refernce datatype ie, it stores the address of data,
in js strings are mutable. /

//creating a string
var string = "devuuzzz";

//to find length of string
console.log("the length is ",string.length)

//to print each letter of string
for(var i=0; i<string.length; i++){
console.log(string[i])
}

//to access any charater in a string

console.log("the charater at the index 3 is -> " ,string[3])

//substring
console.log("the substring is =>",string.substring(0,4))

// ascii value

console.log(string.charCodeAt(2));

var number = "0A";
console.log(number.charCodeAt(1));

//string concatination

console.log("hello my name is " + string + " my age is "+22)

//TYPE CONVERSION
//by default it gets converted to string eg; int -> string
console.log(string + " number is " + 98);

//splitting the string in built methord

var x = "hey there, how is your art going on?"
console.log(x.split(","))
console.log(x.split("there"))