Hello everyone, I started studying javascript and I separated some things that I managed to do:
let school = "Javascript School"; let fullPackage = "JS Pro"; let projects = 4; let awesome = false; console.log(school, fullPackage, projects, awesome);
the one below serves to show the types:
let nome; nome = "Eva" console.log(typeof(nome)); // 'string' nome = 123 console.log(typeof(nome)); // 'number' nome = {} console.log(typeof(nome)); // 'object'
string size:
let s1 = "Melancia"; console.log("Length de s1 = " + s1.length);
accessing each character:
let s1 = "Abacaxi"; console.log(s1[0], s1[1], s1[2], s1[3], s1[4], s1[5], s1[6]);
put everything in capital letters:
let s1 = "Melancia"; console.log(s1.toUpperCase());
remove spaces at the beginning of the string:
let s1 = " Melancia"; console.log(s1.trimStart());
replace the word:
let s1 = "Melancia"; console.log(s1.replace("Melancia", "Melão"));
split strings into substrings:
let s1 = "Melancia é incrível"; console.log(s1.split(" "));
put dashes in the spaces:
let s1 = "Melancia é incrível"; console.log(s1.split(" ").join("-"));
Check if the sentence contains something:
let s1 = "Melancia é incrível"; console.log(s1.includes("Mel"));
That's it guys, I know it's simple but I thought this string manipulation was cool :)
The above is the detailed content of Basic Javascript using VSCode. For more information, please follow other related articles on the PHP Chinese website!