ใช้ Property screen.colorDepth เพื่อดึงจำนวนบิตที่ใช้แสดงสีหนึ่งสีบนหน้าจอ (Bits per Color Component) ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Screen width: + screen.width); document.write(<br>Screen height: + screen.height
ใช้ Property screen.colorDepth เพื่อดึงจำนวนบิตที่ใช้แสดงสีหนึ่งสีบนหน้าจอ (Bits per Color Component) ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Screen width: + screen.width); document.write(<br>Screen height: + screen.height
ใช้ Property screen.pixelDepth เพื่อดึงความลึกของสี (Bits per Pixel) ของหน้าจอผู้ใช้ ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Screen width: + screen.width); document.write(<br>Screen height: + screen.height); document
Property window.scrollY คืนค่าจำนวนพิกเซลที่เอกสารถูก Scroll แนวตั้ง (Vertical) จากมุมซ้ายบนของหน้าต่าง Browser เทียบเท่า window.pageYOffset ตัวอย่างโค้ด <!DOCTYPE html> <html> <head> <style> div { background-color: yellow; height: 1500px;
Property window.scrollX คืนค่าจำนวนพิกเซลที่เอกสารถูก Scroll แนวนอน (Horizontal) จากมุมซ้ายบนของหน้าต่าง Browser เทียบเท่า window.pageXOffset ตัวอย่างโค้ด <!DOCTYPE html> <html> <head> <style> div { background-color: yellow; height: 1500px;
Operator Bitwise XOR (^) ย่อมาจาก Exclusive OR เปรียบเทียบบิตคู่ต่อคู่ ผลลัพธ์เป็น 1 ก็ต่อเมื่อบิตต่างกัน (0 และ 1 หรือ 1 และ 0) หากเหมือนกัน (0-0 หรือ 1-1) จะได้ 0 ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Bitwise XOR Operator<br>)
Operator Signed Right Shift (>>) เลื่อนบิตของตัวเลขไปทางขวา จำนวนบิตที่ระบุ บิตขวาสุดจะหลุดออกไป และ คง Sign Bit (บิตซ้ายสุด) ไว้ เพื่อรักษาเครื่องหมาย (Signed) ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Bitwise Right Shift Operator&
Property document.body ให้การเข้าถึง Element <body> ของเอกสารโดยตรง คืนค่า HTMLBodyElement Object ตัวอย่างโค้ด <!DOCTYPE html> <html> <head> <title>JavaScript Example</title> </head> <body> <p>Demo Text</p> <script>
Property document.embeds คืนค่า HTMLCollection ของ Element <embed> ทั้งหมดในเอกสาร ใช้ .length เพื่อนับจำนวน ตัวอย่างโค้ด <!DOCTYPE html> <html> <head> <title>JavaScript Example</title> </head> <body> <embed src=/html/yourfile.mid wid
Operator Bitwise Left Shift (<<) เลื่อนบิตของตัวเลขไปทางซ้าย จำนวนบิตที่ระบุ และเติม 0 ด้านขวา บิตซ้ายสุดจะหลุดออกไป (Discarded) ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Bitwise Left Shift Operator<br>); // 7 = 00000000
ใช้เมธอด .toString(2) ของ Number เพื่อแปลงเป็น Binary String รองรับทั้ง Positive และ Negative Numbers ตัวอย่างโค้ด ) 0 เพื่อแปลงเป็น Unsigned 32-bit document.write((-7 >>> 0).toString(2)); // ผลลัพธ์: 11111111111111111111111111111001 </script> </body> </html>
Property document.documentElement คืนค่า Root Element ของเอกสาร HTML ซึ่งคือ <html> Element (NodeName = HTML) ตัวอย่างโค้ด <!DOCTYPE html> <html> <head> <title>JavaScript Example</title> </head> <body> <p>Demo Text</p> &l
JavaScript มีวิธีในตัว (Built-in) สำหรับแปลง Binary String เป็น Decimal Number อย่างง่าย วิธีที่ 1: parseInt() กำหนด Radix 2 (แนะนำ) <!DOCTYPE html> <html> <body> <script> var binaryStr = 1010; var decimal = parseInt(binaryStr, 2); document.write(Bina
ใช้ Math.random() ร่วมกับ Math.floor() เพื่อสุ่มจำนวนเต็มในช่วงที่ต้องการ สูตรทั่วไป Math.floor(Math.random() * (max + 1)) สำหรับช่วง 0 ถึง 199 ใช้ Math.floor(Math.random() * 200) ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Math.floor(Math
Property document.head ให้การเข้าถึง Element <head> ของเอกสารโดยตรง คืนค่า HTMLHeadElement Object ตัวอย่างโค้ด <!DOCTYPE html> <html> <head id=myid> <title>JavaScript Example</title> </head> <body> <h1>Employee Information</h1&g
เมธอด sort() เริ่มต้นจะเรียงแบบ String (Lexicographic) ทำให้ [1, 10, 2] กลายเป็น [1, 10, 2] ต้องส่ง Compare Function เข้าไปเพื่อเรียงตัวเลขได้ถูกต้อง ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> var arr = [75, 20, 90, 9, 49, 32, 69, 66]; document.wri
นี่คือกฎและรูปแบบแนะนำ (Code Style) สำหรับการเขียน Object Definitions ใน JavaScript ให้สอดคล้องและอ่านง่าย กฎหลัก String ใช้ Quotes: ค่าที่เป็น String ต้องห่อด้วยเครื่องหมายคำพูด var myBook = new Book(Java, John); Closing Brace บรรทัดใหม่: วาง } บนบรรทัดใหม่ Opening Brace เดียวบรรทัด:
JavaScript Bitwise Operators จัดการตัวเลขเป็นลำดับ 32-bit Signed Integer (Twos Complement) นี่คือรายการ Operator ทั้ง 7 ตัว: ลำดับOperator & ชื่อคำอธิบาย 1& Bitwise ANDทั้งคู่เป็น 1 → 1 2| Bitwise ORบิตไหนบิตหนึ่งเป็น 1 → 1 3^ Bitwise XORบิตต่างกัน (0-1 หรือ 1-0) →
ใช้ Property .target เพื่อดึงค่า target attribute ของลิงก์ ซึ่งกำหนดว่าจะเปิดลิงก์ที่ไหน เช่น หน้าต่างเดียวกัน (_self), หน้าต่างใหม่ (_blank), หรือ Frame เฉพาะ ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <p><a id=anchorid rel=nofollow target=_blank href=https://www.q
ใช้ Property .type เพื่อดึงค่า type attribute ของลิงก์ (<a>) ซึ่งระบุ MIME Type ของเอกสารปลายทาง เช่น text/html, text/css, application/pdf ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <p><a id=anchorid type=text/html target=_blank href=https://www.qries.com/>
Operator Bitwise AND (&) เปรียบเทียบบิตของตัวเลขสองจำนวนแบบคู่ต่อคู่ ผลลัพธ์เป็น 1 ก็ต่อเมื่อทั้งสองบิตเป็น 1 มิฉะนั้นเป็น 0 ตัวอย่างโค้ด <!DOCTYPE html> <html> <body> <script> document.write(Bitwise AND Operator<br>); // 7 = 000000000000000000000