aboutsummaryrefslogtreecommitdiff
path: root/files/vi/glossary/falsy/index.html
blob: 7b39f3e98bd1a57889b0541c62a972a30c0eea00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
title: Falsy
slug: Glossary/Falsy
translation_of: Glossary/Falsy
original_slug: Tu-dien-thuat-ngu/Falsy
---
<p id="Summary">Giá trị <strong>falsy</strong> là giá trị được hiểu là <em>false</em> trong ngữ cảnh {{Glossary("Boolean")}}.</p>

<p>{{Glossary("JavaScript")}} sử dụng {{Glossary("Type_Conversion", "Type Conversion")}} để ép kiểu giá trị bất kì thành Boolean khi cần thiết, ví dụ trong mệnh đề điều kiện ({{Glossary("Conditional", "conditionals")}}) và vòng lặp ({{Glossary("Loop", "loops")}}).</p>

<h2 id="Ví_dụ">Ví dụ</h2>

<p>Sau đây là ví dụ về các giá trị <em>falsy</em> (sẽ được hiểu là 'false' dẫn đến không thực hiện đoạn code của <code>if</code> ):</p>

<pre class="brush: js">if (false)
if (null)
if (undefined)
if (0)
if (NaN)
if ('')
if ("")
if (document.all) [1]</pre>

<p>[1] <code>document.all</code> trước đây được sử dụng trong việc nhận biết trình duyệt và tài liệu <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/obsolete.html#dom-document-all">HTML specification defines a willful violation</a> của chuẩn ECMAScript này để tương thích với code cũ (<code>if (document.all) { // Internet Explorer code here }</code> hoặc sử dụng <code>document.all</code> mà không kiểm tra trước về sự tồn tại của nó: <code>document.all.foo</code>).</p>

<p>Đôi khi từ này được viết là <strong>falsey</strong>.</p>

<h2 id="Tìm_hiểu_thêm">Tìm hiểu thêm</h2>

<ul>
 <li>{{Glossary("Truthy")}}</li>
 <li>{{Glossary("Boolean")}}</li>
</ul>