Automatically translated.View original post

Logical / JavaScript Operator

# Web Site Writing Basics

# javascrip

# The logical operator

Logical Operators in JavaScript use Boolean: true or false) or to control the operation of conditions. They work on a principle called Short-Circuit Evaluation. This means that they may stop evaluating the remaining Operand as soon as the final result is known.

There are 3 main operators:

1. (OR: OR)

The OR operator is used to determine if a condition is true.

Truth table: It returns true if one or both operands are true.

Short-Circuit Operation:

It will evaluate the operand from left to right.

As soon as the first operand is found to be Truthy (considered true), it restores the value of that operand and stops evaluating.

If all operands were Falsy (considered false), it would restore the value of the last operand.

Example Results Reason

'True false. '

'0 5 '

'"null'

General benefit: Used to define Default Value if the first value is null or undefined.

JavaScript

let userName = userSetting | | 'Guest';

/ / If userSetting is null / undefined / "/ 0, userName is set to 'Guest'.

2. & & (AND: AND)

The AND operator is used to determine if all conditions are true.

Truth table: It returns true only if both sides of the operand are true.

Short-Circuit Operation:

It will evaluate the operand from left to right.

As soon as the first operand is found to be Falsy (considered false), it restores the value of that operand and stops evaluating.

If all operands were Truthy, it would restore the value of the last one.

Example Results Reason

The first true & & false false is true, but the second is false, thus restoring false (the second).

5 & & "Hello" "Hello" Both Are Truthy Restore Last

0 & & "World" 0 0 is Falsy immediately returns 0.

Typical Benefits: Used to Make Conditional Rendering or Call Conditional Functions (Used instead of Short If Structures)

JavaScript

/ / If isLogged is true, call the showProfile function.

isLogged & showProfile ();

3.! (NOT: NOT)

The NOT operator is used to reverse the logical value.

Operation: It will convert the operand into a logical value (Boolean) and then reverse it.

! True, false.

! False is true.

Example Results Reason

! True, false. Back up.

! 0 true 0 to Falsy was converted to false and then returned to true.

! "Hello" is true! The first converts "Hello" (Truthy) to false and the second back to true.

Export to sheet

General benefit: Used to verify whether a value is Falsy or Truthy (using!! to convert any value into an authentic Boolean).

Falsy and Truthy Values in JavaScript

In JavaScript logic valuation, the following values are assumed to be Falsy (equivalent to false):

False

0 (zero)

"" (empty string)

Null

Undefined

NaN (Not-a-Number)

Truthy is all other values that are not in the Falsy list (e.g. 1, "hello," [], {}).

2025/10/7 Edited to

... Read moreในบทความนี้เราจะเพิ่มเติมความเข้าใจเกี่ยวกับตัวดำเนินการทางตรรกศาสตร์ (Logical Operators) ใน JavaScript ที่แม้จะเป็นเรื่องพื้นฐานแต่ก็สำคัญมากในการเขียนโปรแกรมที่มีเงื่อนไขซับซ้อน นอกจากนี้ยังมีประเด็นที่หลายคนอาจสงสัยเกี่ยวกับข้อมูลชนิดข้อความ (string) กับการใช้งานตัวดำเนินการเหล่านี้ สิ่งที่อยากแชร์ก็คือการทำงานของตัวดำเนินการ OR (||) และ AND (&&) นอกจากจะช่วยให้เรากำหนดค่าตัวแปรเริ่มต้นได้แบบรวบรัดแล้ว ยังช่วยในกรณีของ Conditional Rendering หรือการเลือกทำงานในบางสถานการณ์อย่างมีประสิทธิภาพ เช่น ถ้ามีค่าของตัวแปรเป็น null หรือ undefined เราสามารถใช้ || กำหนดค่าเป็นค่า default ได้โดยไม่ต้องเขียนโค้ดยาวๆ ส่วนตัวดำเนินการ NOT (!) ก็มีประโยชน์มากในการตรวจสอบว่าค่าตัวไหนเป็น Falsy หรือ Truthy จึงช่วยลดความซับซ้อนในการเขียนเงื่อนไขและทำให้โค้ดอ่านง่ายขึ้นอย่างมาก นอกจากนี้ การเข้าใจเรื่อง Short-Circuit Evaluation ก็สำคัญไม่น้อย เพราะช่วยให้โค้ดที่เราเขียนทำงานได้รวดเร็วและไม่ต้องเสียเวลาในการตรวจสอบเงื่อนไขที่ไม่จำเป็น ในการใช้งานจริง ตัวอย่างเช่น การตรวจสอบสภาวะการล็อกอินผู้ใช้ ถ้าตัวแปร isLogged เป็น true ก็เพียงพอให้เรียกฟังก์ชันแสดงข้อมูลโปรไฟล์ได้ทันที โดยไม่ต้องใช้ if ซ้อนหลายชั้น ซึ่งช่วยให้โค้ดดูสะอาดและเข้าใจง่ายมากขึ้น สำหรับการประเมินค่าตรรกะใน JavaScript นั้น เราควรจดจำค่าที่ถูกมองว่าเป็น Falsy ซึ่งรวมถึง false, 0, "" (สตริงว่าง), null, undefined และ NaN ส่วนค่าที่เหลือจะถือเป็น Truthy ทั้งหมด ซึ่งความรู้ตรงนี้จะช่วยให้เราเขียนเงื่อนไขต่างๆ ได้อย่างถูกต้องและลดข้อผิดพลาด แนะนำว่าควรลองนำตัวดำเนินการเหล่านี้ไปใช้ในโปรเจกต์เล็กๆ หรือในโค้ดที่เขียนเองดู เพื่อเรียนรู้และเข้าใจพฤติกรรมของมันอย่างแท้จริง เพราะประสบการณ์ตรงจะช่วยให้เราเข้าใจแนวคิดและการนำไปใช้ได้ดีกว่าการอ่านอย่างเดียวแน่นอน

Related posts

Cheating isn’t always the worst betrayal. Vengeance by Zane is messy, dramatic, and unapologetically grown. This isn’t sweet romance. This is heartbreak with consequences. If you love urban fiction where the women don’t just cry… they calculate. 📚 Follow for more layered reads. 📖 Full
Brook

Brook

778 likes

Logical self awareness
Therapy helped … with self awareness at least 💁🏼‍♀️
🩷🌵♠️Pony84♠️🌵🩷

🩷🌵♠️Pony84♠️🌵🩷

20 likes

Trump dismantles ABC News with a logical argument
Trump dismantles ABC News with a logical argument. . . #trump2024 #news #florida #trumprally #conservativenews
The Trumpest

The Trumpest

46 likes

Doubting yourself is no longer logical, it’s emotional
It doesn’t make sense to keep doubting yourself. You have so much evidence showing you that you are capable of solving tough problems. You’ve done so much m, you’ve grown so much, and come so far. Doubting yourself is no longer logical, it’s emotional. And probably a habit. You are ready for whatev
Fearlessly Resilient

Fearlessly Resilient

19 likes

TEAS EXAM READING NOTES ✨
TEAS Reading section notes ✨ Clear, simple, and beginner-friendly 📘 Let’s study together and stay motivated 💪 Follow for more TEAS prep! #studygram #nursing #notes #reading #nurse
Megha

Megha

40 likes

The image displays the title "How to Increase your Intelligence (5 tips)" with a person inserting a USB drive into their forehead, symbolizing the input of knowledge to enhance intelligence.
This image presents "Tip # 1: Seek Novelty," advising to explore new activities like learning a language or taking art classes to create neural connections and foster an optimal learning environment.
The image illustrates "Tip # 2: Challenge yourself," encouraging continuous growth by learning new skills once proficient in others, depicted by a person climbing a mountain towards a flag.
🧠 Want to become smarter every day? It’s possible.
Intelligence isn’t just something you’re born with — it’s something you build. Here are 5 simple ways to sharpen your mind daily: Smart choices make a smarter you. Start today. #IncreaseYourIntelligence #DailyGrowth #MindsetMatters #BecomingBetter
Antiya

Antiya

1636 likes

purposeful misunderstanding & logical fallacies? grammarly can help !
BuffUnicorn

BuffUnicorn

863 likes

An image titled "SMELLS - Memory Crossing Time" features burning incense, a lit candle, lavender, and essential oil bottles. The text explains how scents are powerful spiritual messengers, bypassing logic to connect with memory and emotion, and lists common spiritual scent experiences and their meanings.
Spiritual smells
Sometimes Spirit doesn’t speak in words. It drifts in on a scent. A flower with no vase. Coffee when no one’s brewing. Perfume that belongs to someone you loved. Smell travels where time can’t interfere. It bypasses logic and goes straight to memory, emotion, and knowing. If a scent ap
Hug life 🌸

Hug life 🌸

9 likes

#3 gets most believers without them even noticing
1. Distraction – He’ll keep you busy, unfocused, or always “too tired” to pray or read the Word. 2. Deception – Twisting truth to make lies sound logical (just like in Eden). 3. Division – Causing offense, comparison, gossip, and relational strife to break unity. 4.
✞ KEZIAH•MARIE

✞ KEZIAH•MARIE

227 likes

Phallological Museum
The Phallological museum! Iykyk! #phallusmuseum #phallologicalmuseum #terrastravels #terrakimberlyscott #Iceland
TerrasTravels

TerrasTravels

282 likes

Pick a Member of BTS for a Tarot Reading♥️
It’s a BTS pick a card reading! Pick your bias, your bias wrecker, or whatever you feel drawn to for for a tarot reading. 🔮 Remember to take whatever resonates and leave the rest! #tarot #BTS #btsarmy #kpop #tarotreadings
Archer.Arcana

Archer.Arcana

540 likes

Logical?
#helluvaboss
Ava❤️‍🔥

Ava❤️‍🔥

8 likes

Elon Musi Realm
✨ Realm Reading: Elon Musk ✨ 🛸 Starpeople Realm · Incarnated Alien Frequency 🛸 In this realm reading, we explore Elon Musk through the lens of the Starpeople Realm — an incarnated alien consciousness operating within a human body. Starpeople are souls seeded from advanced civilizations beyon
444Jaclyn

444Jaclyn

77 likes

A hooded figure types on a keyboard, surrounded by holographic screens displaying global data and code, with the text overlay "How to become Cyber Security" highlighting the article's focus.
A detailed flowchart illustrates the career path to becoming a cybersecurity professional, from high school studies and university degrees to various certifications, entry-level IT jobs, and specialized cybersecurity roles.
This image outlines essential foundational skills for aspiring cybersecurity professionals, including mathematics (logic, statistics), computer basics (operating systems, hardware), and programming languages like Python, C/C++, and JavaScript.
#cybersecurity #studying #studytok #studywithme #BackToSchool
study with me 📚

study with me 📚

27 likes

Right before you get a love offer.♥️ #etherealkra
Kra'

Kra'

5 likes

What were they thinking?? 🫣 | @TheTyee
Rachel Gilmore

Rachel Gilmore

31 likes

Only logical explanation
#lemon8creator #lemon8partner Indiana #work #workoutfit
tor_cay1

tor_cay1

12 likes

coming back to the states has been hard for sure. I can’t form a logical sentence cuz I can’t believe our world has been watching genoc*de this long and just going on with business as usual.
luluyousefff

luluyousefff

4 likes

The Logical Song
Captivating Logic, Timeless Melody. #classicpop #vintage #timeless #lemon8
Milagros

Milagros

191 likes

Feeling less logical when you are stressed ?
I am an Ambassador for an organization of doctors. Follow for more. #nervoussystemregulation #fightorflight #somatichealing #somatic
howtobehueman

howtobehueman

11 likes

My ex made me realize this…
If only..but that has changed because you don't have to settle or prove who you are or your worth to anyone. If they can't then that's their loss and BAYBAY I may be crazy but I'm also a healer and my logical practical aspects are too notch. I'm literally an asset to any person
☯️YinYang_Life Chronicles🧿

☯️YinYang_Life Chronicles🧿

29 likes

Brinna Donnell

Brinna Donnell

1 like

This image displays verb conjugations for 'have' across various tenses, including Present Simple, Past Simple, Future Simple, Present Continuous, Past Continuous, Present Perfect, Past Perfect, Future Perfect, and Present Perfect Continuous, for different pronouns.
This image lists common medical abbreviations such as ICU, BP, HR, BMI, Dx, Tx, Sx, Rx, Hx, Px, FU, BID, TID, QID, and OD, along with their full meanings.
This image provides a comprehensive list of time vocabulary, including units of time (e.g., 24 hours = 1 day), periods of the day, and various time-related concepts like 'deadline' and 'schedule'.
ለምን?

ለምን?

240 likes

Smartest Zodiac Signs #Zodiac #Lemon8 #astrology✨
DivineDripVibes

DivineDripVibes

6 likes

#workshop #customclothing #clothing-manufacture
#chinafactory #clothingbrand #customclothing #clothing factory #garmentfactory
sevenquan7

sevenquan7

1 like

By the way, part of that antisemitism is suggesting that Jewish people should be and our only safe in a fascist ethnic state, but consequently they will also blame Israel for everything. It does not have to be logical. It just has to be helpful.
Will McC

Will McC

1 like

🌸
Your brain has a preferred way of working! 🧠 Use this palm line hack to find out your true decision-making style. Career success is about working WITH your wiring! 💼 #careergoals #creativity #logic
Master Feng

Master Feng

0 likes

Logical Function in Excel
#lemon8challenge #lemon8badgehunt
DataUnleash

DataUnleash

0 likes

Did you know this happens? #bodycomposition #muscle #calves #doctorexplains
FootDocDana

FootDocDana

0 likes

The Narcissist and Pathological Lying
#fyp #fy #fypシ゚viral #atlanta
Draya A.

Draya A.

10 likes

🥰
Are you a logical analyst or a creative visionary? 🧠🔬 Discover how your brain maps decision-making pathways. Scan your palm at the link in my bio! #intelligence #mindset #logic
Parry Life Gifts

Parry Life Gifts

0 likes

Tarot reading update 🌙✨
#tarot #witch #oracle #psychic #tarotreading
🌷Ambrosia Rose Tarot 🌷

🌷Ambrosia Rose Tarot 🌷

36 likes

Crying releases oxytocin and endorphins aka your brain’s natural sedatives. Bottling it up doesn’t make you strong. It just makes your nervous system tired and petty. Fun fact: For trauma-wired and ADHD brains, crying isn’t emotional chaos ✨ it’s regulation. Letting yourself cry to completion he
Katarina Scott ✨ ECA Tea 🫖

Katarina Scott ✨ ECA Tea 🫖

1 like

The image defines the "no true Scotsman" logical fallacy, explaining it as an appeal to purity to dismiss criticism by shifting goalposts. It includes an example about Scotsmen and porridge, and features an icon of a creature in water.
No Tue Scotsman Logical Fallacy
Alot of Lefties suffer from this textbook logical fallacy about protesting in Portland. Which has led to the inevitable end of the BLM, Roe v Wade, Gaza at PSU & now the current movement. This is NOT "the will of the community." This is a tactic used to divide the community, make everyo
Channel Heed

Channel Heed

2 likes

Your 3-Day Journey to Self-Compassion 🌷
Imagine if you spoke to yourself like someone you deeply care about. 🌸 The Self-Compassion Journal makes that possible in just 3 days. Here’s how it works: 🧠 Left Brain Prompts – Logical, thought-provoking questions to help you understand yourself. 💖 Right Brain Reflections – Gentle exercis
Mind Reflection Method

Mind Reflection Method

2 likes

Replying to @Nick🌙 #ovary #ovariancancer #womenshealth #cancer Legal Disclaimer: The purpose of this post is for educational purposes ONLY. I am a Medical Doctor, but I am NOT your medical doctor. Thus, do NOT consider this post as medical advice - because it is NOT. As always, cons
dr.q | the social M.D.

dr.q | the social M.D.

9 likes

B din strategical & logical not emotional & blinded ☮️🕉️⛎☯️🐍🦅🐯
Jatos211⛎🕉️☯️☮️

Jatos211⛎🕉️☯️☮️

0 likes

Mad, but still logical lmao
Uncle Jimi

Uncle Jimi

30 likes

Joe Dispenza’s method for 30 days… (Game Changer)
Stop waiting for your life to change and start changing your energy. 💡 This breakdown of Dr. Joe Dispenza’s core principles shows you how to move from the "analytical mind" into the "quantum field." If you’re feeling stuck in old patterns, it’s time to achieve heart-brain coherence.
MindsetFreedom

MindsetFreedom

33 likes

Logical
#theguy #comedyskit #funnyvideos #randomhumor #jokes
The Guy

The Guy

15 likes

The image defines the 'Appeal to Common Sense' logical fallacy, describing it as asserting conclusions are 'common sense' without justification. It includes the logical form: 'It's common sense that X is true. Therefore, X is true.'
The image defines the 'Appeal to Common Belief' (argumentum ad populum) logical fallacy, explaining it as using the widespread acceptance of a belief as evidence for its truth, without requiring actual proof.
The image defines the 'Avoiding the Issue' logical fallacy, describing it as responding to an argument by not addressing its points, simply sidestepping the argument. It provides the logical form: 'Person 1 makes claim X. Person 2 makes unrelated statement.'
common logical fallacies
The antiscience community heavily depend on a core group of logical fallacies. #logicalfallacies #science #educational
Allie That RN

Allie That RN

7 likes

Communication tips they don’t teach you
Effective communication isn’t about what you say - it’s about how the other person receives what you say. You can have the most logical point or valid feeling in the world, but if you can’t communicate it in a way that the other person can actually hear, you might as well be speaking different lang
That Feminine Energy

That Feminine Energy

5 likes

A grid-based guide titled '19 Laws of ChatGPT Prompts' by Draven, detailing principles for effective AI interaction. Each law provides a title, explanation, and example, covering clarity, constraints, persona, iteration, and action-oriented prompting to optimize ChatGPT outputs.
19 Laws of ChatGPT Prompts ✨🍋 Need To Know!!
Here’s a high-impact guide for creators and prompt engineers — a cheat sheet of top pointers for writing effective ChatGPT prompts, whether you’re building tools, generating content, or creating immersive experiences. ⸻ 🔹 Top ChatGPT Prompting Pointers Guide for Creators & Prompt Engin
Draven Royce

Draven Royce

26 likes

Decision Reference — Before I Made That Move, I Ch
Ever had that feeling where your pros and cons list is perfectly balanced, but your gut still feels like it’s glitching? I was sitting at my desk yesterday, surrounded by open tabs and half-finished notes, trying to decide on a project pivot that felt way too heavy. Everyone I trusted gave me great
Geri T.

Geri T.

3 likes

What’s logical?
We all face demons, critical thinking and methodical logic should be in your tool bag #criticalthinkinglogic #goals #vision
Jesse’s Blazin Billing

Jesse’s Blazin Billing

2 likes

#citypharma en #paris 📍 26 Rue du Four, 75006 Paris, France #skincare #pharmacy
Emma Duarte

Emma Duarte

3 likes

Pt1 #viral #fypシ゚viral #fypシ #fypage #dating
Yagirlgabby

Yagirlgabby

62 likes

See more