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
以上是JavaScript 用例的詳細內容。更多資訊請關注PHP中文網其他相關文章!