💡 เพื่อน ๆ มือใหม่หัดเขียน JavaScript หลาย ๆ คนอาจจะเคยเห็นเครื่องหมาย ?? และ || ในโปรแกรมแล้วไม่รู้ว่ามันคืออะไร และทำงานยังไง วันนี้เรามาไขข้อสงสัยกันเถอะ !! กับสรุปสั้น ๆ วิธีการใช้งาน Nullish Coalescing Operator
.
มันคืออะไร และใช้งานยังไง หากพร้อมแล้วไปอ่านกันเลยจ้าาาาา~~
.
🌟 Nullish Coalescing Operator
.
Nullish Coalescing (??)
เป็นตัวดำเนินการตรรกะที่จะ Return ค่าทางขวามือเมื่อค่าทางซ้ายเป็น Null หรือ Undefined
.
👨💻 Syntax
leftExpr ?? rightExpr
.
📑 ตัวอย่าง
const name1 = null ?? 'Oreo';
console.log(name1);
//output => Oreo
.
OR (||) - เป็นตัวดำเนินการตรรกะ จะ Return ค่าทางขวามือหากทางซ้ายมือเป็นเท็จ (0, ' ', NaN, null, undefined)
.
📑 ตัวอย่าง
let tu = null;
let text = tu || 'stupid!';
console.log(text); // output => stupid!
.
สามารถใช้ร่วมกับ OR (||) และ AND (&&) ได้แต่ต้องใช้วงเล็บ () เพื่อจัดลำดับความสำคัญของตัวดำเนินการด้วยนะ !!
.
📑 ตัวอย่าง OR (||)
let y = (false || true) ?? "foo"
console.log(y) // output => true
.
📑 ตัวอย่าง AND (&&)
let x = (false && true) ?? "foo"
console.log(x) //output => false
.
💥 Source : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator
.
borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
同時也有10000部Youtube影片,追蹤數超過2,910的網紅コバにゃんチャンネル,也在其Youtube影片中提到,...
「javascript return false」的推薦目錄:
- 關於javascript return false 在 BorntoDev Facebook 的最佳貼文
- 關於javascript return false 在 BorntoDev Facebook 的最讚貼文
- 關於javascript return false 在 コバにゃんチャンネル Youtube 的最佳貼文
- 關於javascript return false 在 大象中醫 Youtube 的最佳貼文
- 關於javascript return false 在 大象中醫 Youtube 的精選貼文
- 關於javascript return false 在 When and why to 'return false' in JavaScript? - Stack Overflow 的評價
- 關於javascript return false 在 Returning true/nothing instead of true/false? - Software ... 的評價
- 關於javascript return false 在 javascript onclick return false - How to use it - YouTube 的評價
- 關於javascript return false 在 return和return false的区别 - Shadownc 的評價
- 關於javascript return false 在 Returning Boolean Values from Functions - GitHub 的評價
javascript return false 在 BorntoDev Facebook 的最讚貼文
🔥 สวัสดีจ้า วันนี้แอดจะมาบอกต่อ 5 ฟีเจอร์เด็ดๆ ของ Javascript Console ที่จะช่วยให้เราสามารถ print log ได้สะดวกมากยิ่งขึ้น มีตัวไหนบ้างไปดูกันเลย
.
⚡ 1) Console Groups - จะทำการ log ค่าออกมาในรูปแบบ Group จะทำให้ดูได้ง่ายมากยิ่งขึ้น
.
📝 วิธีการใช้งาน - เปิดด้วย console.group() และปิดด้วย console.groupEnd(); เช่น
.
console.group("Person Data");
console.log("Name: BorntoDev");
console.log("Age: 4");
console.groupEnd();
console.log("Outside of the group...");
.
⚡ 2) Live Expressions - เป็นฟีเจอร์ของ Google Chrome ที่จะช่วยแสดงผลลัพธ์จากโค้ด JavaScript แบบเรียลไทม์ได้เลย
.
⚡ 3) Timing Your Code - ใช้เพื่อจับเวลาในการทำงานของโค้ด
.
📝 วิธีการใช้งาน - เปิดด้วย console.time() และปิดด้วย console.timeEnd() เช่น
.
console.time("addHeadings");
for (let i = 0; i < 10000; i++) {
document.body.insertAdjacentHTML("beforeend", "
Heading
");}
console.timeEnd("addHeadings");
.
⚡ 4) Styling with CSS - สามารถใส่ CSS Style เวลา print log ออกมาได้เลย เฟี้ยวมาก555
.
📝 วิธีการใช้งาน - โดยจะใช้ร่วมกับ console.log() ใช้ %c ข้างหน้าข้อความที่ต้องการให้แสดง CSS เช่น
.
console.log("I am programer in %cborn to dev co., Ltd.", "color: yellow; font-weight: bold;");
.
⚡ 5) Assertions - ใช้ในการ Debug โค้ดของเราเขียนว่าสามารถทำงานได้ตามจุดประสงค์หรือไม่ ซึ่งจะ return ที่เป็น false เท่านั้น
.
📝 วิธีการใช้งาน - format console.assert(assertion, obj1 [, obj2, ..., objN]); เช่น
.
console.assert(true === true);
console.assert(true === false,"false");
.
จบแล้วกับ 5 ฟีเจอร์เด็ดที่แอดรวบรวมมาให้ ไหนใครลองไปใช้แล้วบ้าง ? หรือมีตัวไหนเด็ดๆนอกจาก 5 อันนี้ ไว้มาบอกต่อกันบ้างนะคร้าบบ 😄
.
borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
javascript return false 在 Returning true/nothing instead of true/false? - Software ... 的推薦與評價
You can't return nothing in JavaScript. Your first example returns undefined. – marstato. May 29 '20 at 17:32. ... <看更多>
相關內容
javascript return false 在 javascript onclick return false - How to use it - YouTube 的推薦與評價

How to use link and onclick event handler to run a javascript without triggering default href behavior! This tip ... ... <看更多>
javascript return false 在 When and why to 'return false' in JavaScript? - Stack Overflow 的推薦與評價
... <看更多>
相關內容