In this post we explore basic javascript use cases.
<div id="box"></div>
const element = document.querySelector("#box"); // Note: only class name, without the '.' element.classList.add("class-name");
function greetUser() { return "Welcome to code to go!"; } let result = greetUser(); console.log(result);
Output:
Welcome to code to go!
let str = "uvais codes"; str = str[0].toUpperCase() + str.substring(1);
Output:
Uvais codes
<div id="box"></div>
const element = document.querySelector("#box"); //change background-color element.style.backgroundColor = "red";
const object = { id: 1, name: "Leanne Graham" }; JSON.stringify(object);
Output"
{"id":1,"name":"Leanne Graham"}
Thanks for Reading
The above is the detailed content of JavaScript Use Cases. For more information, please follow other related articles on the PHP Chinese website!