{"id":78942,"date":"2024-09-30T14:39:33","date_gmt":"2024-09-30T07:39:33","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=78942"},"modified":"2024-09-30T14:39:33","modified_gmt":"2024-09-30T07:39:33","slug":"if-trong-javascript","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/if-trong-javascript\/","title":{"rendered":"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Dinh_nghia_ve_cau_lenh_co_dieu_kien_trong_JavaScript\" >\u0110\u1ecbnh ngh\u0129a v\u1ec1 c\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Cau_lenh_if_trong_JavaScript\" >C\u00e2u l\u1ec7nh if trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Cau_lenh_else_trong_JavaScript\" >C\u00e2u l\u1ec7nh else trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Cau_lenh_if%E2%80%A6else_trong_JavaScript\" >C\u00e2u l\u1ec7nh if&#8230;else trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Cau_lenh_else_if_trong_JavaScript\" >C\u00e2u l\u1ec7nh else if trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Long_cau_lenh_if_trong_JavaScript\" >L\u1ed3ng c\u00e2u l\u1ec7nh if trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Long_cau_lenh_if%E2%80%A6else_trong_JavaScript\" >L\u1ed3ng c\u00e2u l\u1ec7nh if&#8230;else trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Cau_hoi_thuong_gap_ve_if_trong_JavaScript\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 if trong JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/#Tong_ket_ve_cau_lenh_if_trong_JavaScript\" >T\u1ed5ng k\u1ebft v\u1ec1 c\u00e2u l\u1ec7nh if trong JavaScript<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>C\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n cho ph\u00e9p b\u1ea1n th\u1ef1c thi \u0111o\u1ea1n m\u00e3 theo nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n d\u1eef li\u1ec7u kh\u00e1c nhau. M\u1ed9t s\u1ed1 c\u00fa ph\u00e1p \u0111i\u1ec1u ki\u1ec7n ph\u1ed5 bi\u1ebfn c\u00f3 th\u1ec3 k\u1ec3 \u0111\u1ebfn nh\u01b0 c\u00e2u l\u1ec7nh if trong JavaScript, c\u00e2u l\u1ec7nh else, if else ho\u1eb7c else\u2026if. V\u1eady l\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 hi\u1ec3u r\u00f5 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c ph\u1ed5 bi\u1ebfn c\u1ee7a c\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n?<\/strong><\/em><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ecdc b\u00e0i vi\u1ebft sau \u0111\u00e2y \u0111\u1ec3 \u0111\u01b0\u1ee3c gi\u1ea3i \u0111\u00e1p chi ti\u1ebft v\u1ec1:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1ecbnh ngh\u0129a v\u1ec1 c\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n trong JavaScript<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c d\u1ea1ng c\u00e2u l\u1ec7nh if trong JavaScript ph\u1ed5 bi\u1ebfn<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Dinh_nghia_ve_cau_lenh_co_dieu_kien_trong_JavaScript\"><\/span><b> \u0110\u1ecbnh ngh\u0129a v\u1ec1 c\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n trong JavaScript cho ph\u00e9p b\u1ea1n th\u1ef1c thi c\u00e1c kh\u1ed1i m\u00e3 c\u1ee5 th\u1ec3 d\u1ef1a tr\u00ean c\u00e1c \u0111i\u1ec1u ki\u1ec7n. N\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang, kh\u1ed1i m\u00e3 s\u1ebd \u0111\u01b0\u1ee3c ch\u1ea1y, ng\u01b0\u1ee3c l\u1ea1i n\u1ebfu \u0111i\u1ec1u ki\u1ec7n sai, m\u1ed9t kh\u1ed1i m\u00e3 kh\u00e1c s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi d\u1ef1a tr\u00ean \u0111i\u1ec1u ki\u1ec7n.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t s\u1ed1 ph\u01b0\u01a1ng ph\u00e1p ph\u1ed5 bi\u1ebfn \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n, c\u1ee5 th\u1ec3 nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u1ef1c thi m\u1ed9t \u0111o\u1ea1n m\u00e3 n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh l\u00e0 \u0111\u00fang<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh else<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u1ef1c thi m\u1ed9t \u0111o\u1ea1n m\u00e3 n\u1ebfu \u0111i\u1ec1u ki\u1ec7n t\u01b0\u01a1ng t\u1ef1 c\u1ee7a c\u00e2u l\u1ec7nh if tr\u01b0\u1edbc \u0111\u00f3 sai.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if&#8230;else<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u1ef1c thi m\u1ed9t kh\u1ed1i m\u00e3 ch\u1ec9 khi m\u1ed9t \u0111i\u1ec1u ki\u1ec7n c\u1ee5 th\u1ec3 \u0111\u01b0\u1ee3c \u0111\u00e1p \u1ee9ng<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh else if<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u00eam nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n h\u01a1n v\u00e0o c\u00e2u l\u1ec7nh if, cho ph\u00e9p ki\u1ec3m tra nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n thay th\u1ebf.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh nested-if<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Cho ph\u00e9p l\u1ed3ng c\u00e1c c\u00e2u l\u1ec7nh if v\u00e0o trong c\u00e1c c\u00e2u l\u1ec7nh if. M\u1ed9t c\u00e2u l\u1ec7nh if l\u1ed3ng nhau ngh\u0129a l\u00e0 c\u00e2u l\u1ec7nh if s\u1ebd l\u00e0 m\u1ee5c ti\u00eau c\u1ee7a m\u1ed9t c\u00e2u l\u1ec7nh if ho\u1eb7c c\u00e2u l\u1ec7nh else kh\u00e1c.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Nested if else<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Cho ph\u00e9p ki\u1ec3m tra nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n theo c\u00e1ch ph\u00e2n c\u1ea5p.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span class=\"ez-toc-section\" id=\"Cau_lenh_if_trong_JavaScript\"><\/span><b>C\u00e2u l\u1ec7nh if trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if l\u00e0 m\u1ed9t c\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 quy\u1ebft \u0111\u1ecbnh m\u1ed9t c\u00e2u l\u1ec7nh ho\u1eb7c kh\u1ed1i l\u1ec7nh n\u00e0o \u0111\u00f3 \u0111\u01b0\u1ee3c th\u1ef1c thi hay kh\u00f4ng. N\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang, \u0111o\u1ea1n m\u00e3 s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p c\u1ee7a c\u00e2u l\u1ec7nh if nh\u01b0 sau:\u00a0<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">if<\/span> <span style=\"font-weight: 400;\">(condition)<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\/\/ N\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang, <\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\/\/ \u0111o\u1ea1n m\u00e3 s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi.<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if ch\u1ea5p nh\u1eadn b\u1ea5t k\u1ef3 bi\u1ec3u th\u1ee9c \u0111i\u1ec1u ki\u1ec7n n\u00e0o, kh\u00f4ng ch\u1ec9 gi\u00e1 tr\u1ecb boolean. N\u1ebfu bi\u1ec3u th\u1ee9c \u0111i\u1ec1u ki\u1ec7n tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb truthy (\u0111\u00fang) ho\u1eb7c falsy (sai) th\u00ec c\u00e2u l\u1ec7nh if s\u1ebd d\u1ef1a v\u00e0o \u0111\u00f3 \u0111\u1ec3 quy\u1ebft \u0111\u1ecbnh c\u00f3 th\u1ef1c thi kh\u1ed1i m\u00e3 hay kh\u00f4ng. Ch\u1eb3ng h\u1ea1n nh\u01b0 \u0111i\u1ec1u ki\u1ec7n l\u00e0 m\u1ed9t s\u1ed1 kh\u00e1c kh\u00f4ng, m\u1ed9t chu\u1ed7i kh\u00f4ng r\u1ed7ng ho\u1eb7c m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng,&#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5, m\u00e3 JavaScript x\u00e1c \u0111\u1ecbnh bi\u1ebfn \u201cnum\u201d l\u00e0 ch\u1eb5n hay l\u1ebb b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng to\u00e1n t\u1eed modulo %. N\u1ebfu \u201cnum\u201d chia h\u1ebft cho 2 m\u00e0 kh\u00f4ng c\u00f3 d\u01b0, ch\u00fang s\u1ebd hi\u1ec3n th\u1ecb \u201cS\u1ed1 \u0111\u00e3 cho l\u00e0 s\u1ed1 ch\u1eb5n\u201d. Ng\u01b0\u1ee3c l\u1ea1i, ch\u00fang s\u1ebd hi\u1ec3n th\u1ecb \u201cs\u1ed1 \u0111\u00e3 cho l\u00e0 s\u1ed1 l\u1ebb\u201d.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">let<\/span> <span style=\"font-weight: 400;\">num<\/span><span style=\"font-weight: 400;\"> = <\/span><span style=\"font-weight: 400;\">20<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">num<\/span> <span style=\"font-weight: 400;\">%<\/span> <span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> === <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"S\u1ed1 \u0111\u00e3 cho l\u00e0 s\u1ed1 ch\u1eb5n\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">num<\/span> <span style=\"font-weight: 400;\">%<\/span> <span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> !== <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"S\u1ed1 \u0111\u00e3 cho l\u00e0 s\u1ed1 l\u1ebb\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">};<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Cau_lenh_else_trong_JavaScript\"><\/span><b>C\u00e2u l\u1ec7nh else trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">B\u1ea1n s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh else \u0111\u1ec3 th\u1ef1c thi \u0111o\u1ea1n m\u00e3 khi \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh trong c\u00e2u l\u1ec7nh if tr\u01b0\u1edbc \u0111\u00f3 \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 l\u00e0 sai.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p c\u1ee7a c\u00e2u l\u1ec7nh else nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">if (condition) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/ kh\u1ed1i code<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/<\/span><span style=\"font-weight: 400;\"> th\u1ef1c thi khi di\u1ec1u ki\u1ec7n \u0111\u00fang<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">else {<\/span>\r\n<span style=\"font-weight: 400;\">  \u00a0 \/\/ kh\u1ed1i code<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/<\/span><span style=\"font-weight: 400;\"> th\u1ef1c thi khi di\u1ec1u ki\u1ec7n sai<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">N\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang, \u0111o\u1ea1n m\u00e3 trong if s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi v\u00e0 m\u00e3 b\u00ean trong else b\u1ecb b\u1ecf qua.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ng\u01b0\u1ee3c l\u1ea1i, n\u1ebfu \u0111i\u1ec1u ki\u1ec7n l\u00e0 sai, m\u00e3 b\u00ean trong if s\u1ebd b\u1ecb b\u1ecf qua v\u00e0 m\u00e3 trong else s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cau_lenh_if%E2%80%A6else_trong_JavaScript\"><\/span><b>C\u00e2u l\u1ec7nh if&#8230;else trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>C\u00e2u l\u1ec7nh if-else s\u1ebd th\u1ef1c hi\u1ec7n m\u1ed9t s\u1ed1 h\u00e0nh \u0111\u1ed9ng d\u1ef1a tr\u00ean m\u1ed9t \u0111i\u1ec1u ki\u1ec7n c\u1ee5 th\u1ec3:<\/p>\n<ul>\n<li>N\u1ebfu \u0111i\u1ec1u ki\u1ec7n trong if l\u00e0 \u0111\u00fang, kh\u1ed1i l\u1ec7nh trong if s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi;<\/li>\n<li>N\u1ebfu \u0111i\u1ec1u ki\u1ec7n sai, kh\u1ed1i l\u1ec7nh trong else s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi (n\u1ebfu c\u00f3);<\/li>\n<li>Kh\u1ed1i else kh\u00f4ng c\u00f3 \u0111i\u1ec1u ki\u1ec7n ri\u00eang v\u00e0 ch\u1ec9 ch\u1ea1y khi \u0111i\u1ec1u ki\u1ec7n if kh\u00f4ng \u0111\u00fang.<\/li>\n<\/ul>\n<p>C\u00fa ph\u00e1p c\u1ee7a if&#8230;else nh\u01b0 sau:<\/p>\n<pre>if (condition) {\r\n  \/\/ kh\u1ed1i code s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang\r\n} else {\r\n  \/\/ kh\u1ed1i code s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi n\u1ebfu \u0111i\u1ec1u ki\u1ec7n sai\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5, m\u00e3 JavaScript sau ki\u1ec3m tra bi\u1ebfn \u201cage\u201d c\u00f3 l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng 18 kh\u00f4ng. N\u1ebfu \u0111\u00fang, k\u1ebft qu\u1ea3 s\u1ebd ghi l\u1ea1i \u201cB\u1ea1n \u0111\u1ee7 \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c c\u1ea5p gi\u1ea5y ph\u00e9p l\u00e1i xe\u201d, n\u1ebfu kh\u00f4ng k\u1ebft qu\u1ea3 s\u1ebd hi\u1ec3n th\u1ecb ng\u01b0\u1ee3c l\u1ea1i. \u0110i\u1ec1u n\u00e0y s\u1ebd cho bi\u1ebft \u0111i\u1ec1u ki\u1ec7n \u0111\u1ec3 \u0111\u01b0\u1ee3c c\u1ea5p ph\u00e9p l\u00e1i xe d\u1ef1a tr\u00ean \u0111\u1ed9 tu\u1ed5i.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">let<\/span><span style=\"font-weight: 400;\"> age = <\/span><span style=\"font-weight: 400;\">25<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (age &gt;= <\/span><span style=\"font-weight: 400;\">18<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"B\u1ea1n \u0111\u1ee7 \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c c\u1ea5p gi\u1ea5y ph\u00e9p l\u00e1i xe!\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span><span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"B\u1ea1n kh\u00f4ng \u0111\u1ee7 \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c c\u1ea5p gi\u1ea5y ph\u00e9p l\u00e1i xe!\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">};<\/span><\/pre>\n<p>K\u1ebft qu\u1ea3 hi\u1ec3n th\u1ecb:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">B\u1ea1n \u0111\u1ee7 \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c c\u1ea5p gi\u1ea5y ph\u00e9p l\u00e1i xe!<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span class=\"ez-toc-section\" id=\"Cau_lenh_else_if_trong_JavaScript\"><\/span><b>C\u00e2u l\u1ec7nh else if trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Trong JavaScript, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh else if \u0111\u1ec3 ki\u1ec3m tra nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n kh\u00e1c nhau. C\u00fa ph\u00e1p c\u1ee5 th\u1ec3 c\u1ee7a c\u00e2u l\u1ec7nh nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/<\/span><span style=\"font-weight: 400;\"> ki\u1ec3m tra \u0111i\u1ec1u ki\u1ec7n \u0111\u1ea7u ti\u00ean\r\n<\/span><span style=\"font-weight: 400;\">if <\/span><span style=\"font-weight: 400;\">(condition1) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/<\/span><span style=\"font-weight: 400;\"> if <\/span><span style=\"font-weight: 400;\">body<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/<\/span><span style=\"font-weight: 400;\"> ki\u1ec3m tra <\/span><span style=\"font-weight: 400;\">\u0111i\u1ec1u ki\u1ec7n th\u1ee9 hai<\/span>\r\n<span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> if <\/span><span style=\"font-weight: 400;\">(condition2){<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/ else<\/span><span style=\"font-weight: 400;\"> if <\/span><span style=\"font-weight: 400;\">body<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/<\/span><span style=\"font-weight: 400;\"> if <\/span><span style=\"font-weight: 400;\">kh\u00f4ng c\u00f3 \u0111i\u1ec1u ki\u1ec7n t\u01b0\u01a1ng \u1ee9ng<\/span>\r\n<span style=\"font-weight: 400;\">else {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/ else body<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3,<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1ea7u ti\u00ean, \u0111i\u1ec1u ki\u1ec7n trong c\u00e2u l\u1ec7nh if s\u1ebd \u0111\u01b0\u1ee3c ki\u1ec3m tra, n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang th\u00ec \u0111o\u1ea1n m\u00e3 s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi, ph\u1ea7n \u0111i\u1ec1u ki\u1ec7n c\u00f2n l\u1ea1i \u0111\u01b0\u1ee3c b\u1ecf qua.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">N\u1ebfu kh\u00f4ng, \u0111i\u1ec1u ki\u1ec7n trong c\u00e2u l\u1ec7nh else if s\u1ebd \u0111\u01b0\u1ee3c ki\u1ec3m tra. K\u1ebft qu\u1ea3 \u0111\u00fang th\u00ec \u0111o\u1ea1n m\u00e3 s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi v\u00e0 t\u1ef1 \u0111\u1ed9ng qua b\u1ecf qua ph\u1ea7n \u0111i\u1ec1u ki\u1ec7n c\u00f2n l\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Cu\u1ed1i c\u00f9ng, n\u1ebfu kh\u00f4ng c\u00f3 \u0111i\u1ec1u ki\u1ec7n n\u00e0o kh\u1ea3 thi, kh\u1ed1i m\u00e3 s\u1ebd th\u1ef1c thi \u0111i\u1ec1u ki\u1ec7n trong else.\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 v\u1ec1 c\u00e1ch s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh else if nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">let <\/span><span style=\"font-weight: 400;\">rating<\/span><span style=\"font-weight: 400;\"> = <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">rating<\/span><span style=\"font-weight: 400;\"> &lt;= <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"Rating t\u1ec7\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">else<\/span> <span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">rating<\/span><span style=\"font-weight: 400;\"> &gt;= <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"Rating t\u1ed1t\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"Rating trung b\u00ecnh\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Output: Rating t\u1ed1t!<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u1ede v\u00ed d\u1ee5 tr\u00ean, c\u00f3 th\u1ec3 th\u1ea5y:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 ki\u1ec3m tra \u0111i\u1ec1u ki\u1ec7n rating &lt;=2<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">T\u01b0\u01a1ng t\u1ef1, c\u00e2u l\u1ec7nh else if \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 ki\u1ec3m tra \u0111i\u1ec1u ki\u1ec7n kh\u00e1c l\u00e0 rating &gt;=4<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">V\u00ec khi \u0111i\u1ec1u ki\u1ec7n else if \u0111\u01b0\u1ee3c th\u1ecfa m\u00e3n, n\u00ean m\u00e3 b\u00ean trong n\u00f3 s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Long_cau_lenh_if_trong_JavaScript\"><\/span><b>L\u1ed3ng c\u00e2u l\u1ec7nh if trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">B\u00ean c\u1ea1nh th\u1ef1c hi\u1ec7n c\u00e2u l\u1ec7nh \u0111\u01a1n, b\u1ea1n c\u0169ng c\u00f3 th\u1ec3 l\u1ed3ng c\u00e1c c\u00e2u l\u1ec7nh if v\u00e0o v\u1edbi nhau, t\u1ee9c l\u00e0 \u0111\u1eb7t m\u1ed9t c\u00e2u l\u1ec7nh if b\u00ean trong m\u1ed9t c\u00e2u l\u1ec7nh if kh\u00e1c. Khi m\u1ed9t c\u00e2u l\u1ec7nh if l\u1ed3ng v\u00e0o nhau, ngh\u0129a l\u00e0 c\u00e2u l\u1ec7nh \u0111\u00f3 s\u1ebd l\u00e0 m\u1ee5c ti\u00eau c\u1ee7a m\u1ed9t c\u00e2u l\u1ec7nh if ho\u1eb7c else kh\u00e1c.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (condition1) <\/span>\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \/\/ Th\u1ef1c thi khi condition1 \u0111\u00fang<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 <\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (condition2) <\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 {<\/span>\r\n<span style=\"font-weight: 400;\">  \u00a0 \u00a0 \/\/ Th\u1ef1c thi khi condition2 \u0111\u00fang<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 v\u1ec1 c\u00e2u l\u1ec7nh if l\u1ed3ng nhau nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">let<\/span><span style=\"font-weight: 400;\"> i = <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (i == <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">) { <\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (i &lt; <\/span><span style=\"font-weight: 400;\">15<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"i nh\u1ecf h\u01a1n 15\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (i &lt; <\/span><span style=\"font-weight: 400;\">12<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"i c\u0169ng nh\u1ecf h\u01a1n 12\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">else<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"i l\u1edbn h\u01a1n 15\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Long_cau_lenh_if%E2%80%A6else_trong_JavaScript\"><\/span><b>L\u1ed3ng c\u00e2u l\u1ec7nh if&#8230;else trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Khi s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh if else b\u00ean trong m\u1ed9t c\u00e2u l\u1ec7nh if else kh\u00e1c, b\u1ea1n s\u1ebd t\u1ea1o ra logic \u0111i\u1ec1u ki\u1ec7n ph\u1ee9c t\u1ea1p b\u1eb1ng c\u00e1ch ki\u1ec3m tra nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n theo c\u00e1ch ph\u00e2n c\u1ea5p. M\u1ed7i c\u00e2u l\u1ec7nh if c\u00f3 th\u1ec3 c\u00f3 m\u1ed9t kh\u1ed1i else li\u00ean quan v\u00e0 trong m\u1ed7i c\u00e2u l\u1ec7nh if ho\u1eb7c else, b\u1ea1n c\u00f3 th\u1ec3 l\u1ed3ng m\u1ed9t c\u00e2u l\u1ec7nh if else kh\u00e1c.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Vi\u1ec7c l\u1ed3ng nhau n\u00e0y c\u00f3 th\u1ec3 ti\u1ebfp t\u1ee5c \u1edf nhi\u1ec1u c\u1ea5p \u0111\u1ed9, nh\u01b0ng \u0111i\u1ec1u quan tr\u1ecdng l\u00e0 ph\u1ea3i duy tr\u00ec \u0111\u01b0\u1ee3c kh\u1ea3 n\u0103ng \u0111\u1ecdc c\u1ee7a \u0111o\u1ea1n m\u00e3 \u0111\u01a1n gi\u1ea3n v\u00e0 t\u1ed1i \u01b0u h\u00f3a, tr\u00e1nh s\u1ef1 ph\u1ee9c t\u1ea1p qu\u00e1 m\u1ee9c.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ch\u1eb3ng h\u1ea1n nh\u01b0 v\u00ed d\u1ee5 sau \u0111\u00e2y:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">let<\/span><span style=\"font-weight: 400;\"> weather = <\/span><span style=\"font-weight: 400;\">\"n\u1eafng\"<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n<span style=\"font-weight: 400;\">let<\/span><span style=\"font-weight: 400;\"> temperature = <\/span><span style=\"font-weight: 400;\">25<\/span><span style=\"font-weight: 400;\">;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (weather === <\/span><span style=\"font-weight: 400;\">\"n\u1eafng\"<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (temperature &gt; <\/span><span style=\"font-weight: 400;\">30<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"H\u00f4m nay th\u1eddi ti\u1ebft n\u00f3ng b\u1ee9c!\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 } <\/span><span style=\"font-weight: 400;\">else<\/span> <span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (temperature &gt; <\/span><span style=\"font-weight: 400;\">20<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"M\u1ed9t ng\u00e0y th\u1eadt l\u00e0 \u1ea5m \u00e1p!\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 } <\/span><span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"Th\u1eddi ti\u1ebft h\u00f4m nay c\u00f3 ch\u00fat l\u1ea1nh\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span><span style=\"font-weight: 400;\">else<\/span> <span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (weather === <\/span><span style=\"font-weight: 400;\">\"m\u01b0a\"<\/span><span style=\"font-weight: 400;\">) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"Nh\u1edb mang theo \u00f4 nh\u00e9!\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">} <\/span><span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 console.<\/span><span style=\"font-weight: 400;\">log<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"Nh\u1edb ki\u1ec3m tra th\u1eddi ti\u1ebft tr\u01b0\u1edbc khi qua ngo\u00e0i nh\u00e9!\"<\/span><span style=\"font-weight: 400;\">);<\/span>\r\n<span style=\"font-weight: 400;\">};<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u1ede v\u00ed d\u1ee5 tr\u00ean, c\u00f3 th\u1ec3 th\u1ea5y:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh if b\u00ean ngo\u00e0i s\u1ebd ki\u1ec3m tra bi\u1ebfn \u201cth\u1eddi ti\u1ebft\u201d<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">N\u1ebfu tr\u1eddi \u201cn\u1eafng\u201d, n\u00f3 s\u1ebd ki\u1ec3m tra th\u00eam bi\u1ebfn nhi\u1ec7t \u0111\u1ed9 \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh lo\u1ea1i ng\u00e0y (n\u00f3ng, \u1ea5m ho\u1eb7c l\u1ea1nh)<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">T\u00f9y theo gi\u00e1 tr\u1ecb th\u1eddi ti\u1ebft v\u00e0 nhi\u1ec7t \u0111\u1ed9 m\u00e0 c\u00e1c th\u00f4ng b\u00e1o kh\u00e1c nhau s\u1ebd \u0111\u01b0\u1ee3c ghi v\u00e0o b\u1ea3ng \u0111i\u1ec1u khi\u1ec3n.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_if_trong_JavaScript\"><\/span><b>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 if trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>C\u00f3 th\u1ec3 d\u00f9ng nhi\u1ec1u h\u01a1n 3 \u0111i\u1ec1u ki\u1ec7n trong c\u00e2u l\u1ec7nh if kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n trong m\u1ed9t c\u00e2u l\u1ec7nh if b\u1eb1ng c\u00e1ch k\u1ebft h\u1ee3p c\u00e1c \u0111i\u1ec1u ki\u1ec7n v\u1edbi to\u00e1n t\u1eed logic nh\u01b0 \u201cand\u201d (&amp;&amp;) ho\u1eb7c \u201cor\u201d (||) ho\u1eb7c c\u1ea3 hai.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (cond1 <\/span><span style=\"font-weight: 400;\">AND<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">OR<\/span><span style=\"font-weight: 400;\"> COND2) <\/span><span style=\"font-weight: 400;\">AND<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">OR<\/span><span style=\"font-weight: 400;\"> (cond3 <\/span><span style=\"font-weight: 400;\">AND<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">OR<\/span><span style=\"font-weight: 400;\"> cond4):<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 code1<\/span>\r\n<span style=\"font-weight: 400;\">else<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 code2<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u201cAND\u201d<\/b><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n khi c\u1ea3 hai \u0111i\u1ec1u ki\u1ec7n \u0111\u1ec1u \u0111\u00fang. N\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u1ea7u ti\u00ean sai, tr\u00ecnh duy\u1ec7t s\u1ebd kh\u00f4ng ki\u1ec3m tra \u0111i\u1ec1u ki\u1ec7n th\u1ee9 hai. Ng\u01b0\u1ee3c l\u1ea1i, n\u1ebfu \u0111i\u1ec1u ki\u1ec7n c\u00e2u \u0111\u1ea7u ti\u00ean \u0111\u00fang, h\u1ec7 th\u1ed1ng s\u1ebd chuy\u1ec3n \u0111\u1ebfn \u0111i\u1ec1u ki\u1ec7n th\u1ee9 hai v\u00e0 n\u1ebfu n\u00f3 sai, false s\u1ebd \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 c\u00e2u l\u1ec7nh if.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u201cOR\u201d<\/b><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n v\u1edbi b\u1ea5t k\u1ef3 \u0111i\u1ec1u ki\u1ec7n n\u00e0o c\u0169ng c\u1ea7n ph\u1ea3i \u0111\u00fang v\u00e0 n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u1ea7u ti\u00ean \u0111\u00fang, \u0111o\u1ea1n m\u00e3 s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi m\u00e0 kh\u00f4ng c\u1ea7n \u0111\u00e1nh gi\u00e1 ti\u1ebfp \u0111i\u1ec1u ki\u1ec7n th\u1ee9 hai.\u00a0<\/span><\/li>\n<\/ul>\n<h3><b>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c c\u00e2u \u0111i\u1ec1u ki\u1ec7n n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">T\u00f9y theo c\u1ea5u tr\u00fac \u0111o\u1ea1n m\u00e3 v\u00e0 nhu c\u1ea7u s\u1eed d\u1ee5ng m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 c\u00e2n nh\u1eafc l\u1ef1a ch\u1ecdn ph\u01b0\u01a1ng th\u1ee9c c\u00e2u \u0111i\u1ec1u ki\u1ec7n th\u00edch h\u1ee3p, c\u1ee5 th\u1ec3 nh\u01b0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u00e2u l\u1ec7nh if:<\/b><span style=\"font-weight: 400;\"> \u0110\u01b0\u1ee3c s\u1eed d\u1ee5ng khi b\u1ea1n ch\u1ec9 c\u1ea7n ki\u1ec3m tra m\u1ed9t \u0111i\u1ec1u ki\u1ec7n v\u00e0 th\u1ef1c hi\u1ec7n m\u1ed9t h\u00e0nh \u0111\u1ed9ng n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00f3 \u0111\u00fang. \u0110\u1ed3ng th\u1eddi, n\u00f3 kh\u00f4ng y\u00eau c\u1ea7u ph\u1ea3i c\u00f3 else.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u00e2u l\u1ec7nh else:<\/b><span style=\"font-weight: 400;\"> \u0110\u00e2y kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t c\u00e2u l\u1ec7nh \u0111\u1ed9c l\u1eadp m\u00e0 l\u00e0 m\u1ed9t ph\u1ea7n c\u1ee7a c\u00e2u l\u1ec7nh if else. Khi b\u1ea1n mu\u1ed1n th\u1ef1c hi\u1ec7n m\u1ed9t h\u00e0nh \u0111\u1ed9ng kh\u00e1c n\u1ebfu \u0111i\u1ec1u ki\u1ec7n c\u1ee7a c\u00e2u l\u1ec7nh if kh\u00f4ng \u0111\u00fang, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng else.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u00e2u l\u1ec7nh if else:<\/b><span style=\"font-weight: 400;\"> C\u00e2u l\u1ec7nh \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng khi b\u1ea1n c\u1ea7n ki\u1ec3m tra m\u1ed9t \u0111i\u1ec1u ki\u1ec7n v\u00e0 th\u1ef1c hi\u1ec7n m\u1ed9t h\u00e0nh \u0111\u1ed9ng n\u1ebfu \u0111i\u1ec1u ki\u1ec7n \u0111\u00fang. \u0110\u1ed3ng th\u1eddi th\u1ef1c hi\u1ec7n m\u1ed9t h\u00e0nh \u0111\u1ed9ng kh\u00e1c n\u1ebfu \u0111i\u1ec1u ki\u1ec7n sai.\u00a0<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_ve_cau_lenh_if_trong_JavaScript\"><\/span><b>T\u1ed5ng k\u1ebft v\u1ec1 c\u00e2u l\u1ec7nh if trong JavaScript<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh <\/span><b>if trong JavaScript<\/b><span style=\"font-weight: 400;\"> l\u00e0 m\u1ed9t trong nh\u1eefng c\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n quan tr\u1ecdng. B\u1eb1ng c\u00e1ch hi\u1ec3u r\u00f5 c\u00e1ch s\u1eed d\u1ee5ng if, b\u1ea1n c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng \u1ee9ng d\u1ee5ng v\u00e0o c\u00f4ng vi\u1ec7c c\u0169ng nh\u01b0 n\u00e2ng cao k\u1ef9 n\u0103ng c\u1ee7a b\u1ea3n th\u00e2n. Linh ho\u1ea1t \u1ee9ng d\u1ee5ng c\u00e2u l\u1ec7nh if v\u00e0o c\u00e1c d\u1ef1 \u00e1n th\u1ef1c t\u1ebf \u0111\u1ec3 kh\u00e1m ph\u00e1 th\u00eam c\u00e1c c\u00e2u l\u1ec7nh li\u00ean quan kh\u00e1c nh\u01b0 loop, break ho\u1eb7c continue b\u1ea1n nh\u00e9!<\/span><\/p>\n<blockquote><p><i>Xem th\u00eam:<\/i> <strong><a href=\"https:\/\/itviec.com\/blog\/javascript-developer\/\"><i>JavaScript Developer l\u00e0 g\u00ec? C\u00e1c h\u01b0\u1edbng ph\u00e1t tri\u1ec3n c\u1ee7a JavaScript Developer<\/i><\/a><\/strong><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>C\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n cho ph\u00e9p b\u1ea1n th\u1ef1c thi \u0111o\u1ea1n m\u00e3 theo nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n d\u1eef li\u1ec7u kh\u00e1c nhau. M\u1ed9t s\u1ed1 c\u00fa ph\u00e1p \u0111i\u1ec1u ki\u1ec7n ph\u1ed5 bi\u1ebfn c\u00f3 th\u1ec3 k\u1ec3 \u0111\u1ebfn nh\u01b0 c\u00e2u l\u1ec7nh if trong JavaScript, c\u00e2u l\u1ec7nh else, if else ho\u1eb7c else\u2026if. V\u1eady l\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 hi\u1ec3u r\u00f5 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c [&hellip;]<\/p>\n","protected":false},"author":207,"featured_media":79222,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-78942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft - ITviec Blog<\/title>\n<meta name=\"description\" content=\"M\u1ed9t s\u1ed1 l\u1ec7nh \u0111i\u1ec1u ki\u1ec7n ph\u1ed5 bi\u1ebfn nh\u01b0 if trong JavaScript, c\u00e2u l\u1ec7nh else, if else ho\u1eb7c else\u2026if. H\u1ecdc c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh \u0111i\u1ec1u ki\u1ec7n ngay.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft\" \/>\n<meta property=\"og:description\" content=\"C\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n cho ph\u00e9p b\u1ea1n th\u1ef1c thi \u0111o\u1ea1n m\u00e3 theo nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n d\u1eef li\u1ec7u kh\u00e1c nhau. M\u1ed9t s\u1ed1 c\u00fa ph\u00e1p \u0111i\u1ec1u ki\u1ec7n ph\u1ed5 bi\u1ebfn c\u00f3 th\u1ec3 k\u1ec3 \u0111\u1ebfn nh\u01b0 c\u00e2u l\u1ec7nh\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/if-trong-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-30T07:39:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/09\/if-trong-JavaScript-vippro.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"790\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Uyen Ngo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Uyen Ngo\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft - ITviec Blog","description":"M\u1ed9t s\u1ed1 l\u1ec7nh \u0111i\u1ec1u ki\u1ec7n ph\u1ed5 bi\u1ebfn nh\u01b0 if trong JavaScript, c\u00e2u l\u1ec7nh else, if else ho\u1eb7c else\u2026if. H\u1ecdc c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh \u0111i\u1ec1u ki\u1ec7n ngay.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/if-trong-javascript\/","og_locale":"vi_VN","og_type":"article","og_title":"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft","og_description":"C\u00e2u l\u1ec7nh c\u00f3 \u0111i\u1ec1u ki\u1ec7n cho ph\u00e9p b\u1ea1n th\u1ef1c thi \u0111o\u1ea1n m\u00e3 theo nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n d\u1eef li\u1ec7u kh\u00e1c nhau. M\u1ed9t s\u1ed1 c\u00fa ph\u00e1p \u0111i\u1ec1u ki\u1ec7n ph\u1ed5 bi\u1ebfn c\u00f3 th\u1ec3 k\u1ec3 \u0111\u1ebfn nh\u01b0 c\u00e2u l\u1ec7nh","og_url":"https:\/\/itviec.com\/blog\/if-trong-javascript\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2024-09-30T07:39:33+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/09\/if-trong-JavaScript-vippro.jpg","type":"image\/jpeg"}],"author":"Uyen Ngo","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Uyen Ngo","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"9 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/"},"author":{"name":"Uyen Ngo","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/f4cd1226846e0258c664e170d3e52d20"},"headline":"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft","datePublished":"2024-09-30T07:39:33+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/"},"wordCount":2373,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/09\/if-trong-JavaScript-vippro.jpg","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/","url":"https:\/\/itviec.com\/blog\/if-trong-javascript\/","name":"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/09\/if-trong-JavaScript-vippro.jpg","datePublished":"2024-09-30T07:39:33+00:00","description":"M\u1ed9t s\u1ed1 l\u1ec7nh \u0111i\u1ec1u ki\u1ec7n ph\u1ed5 bi\u1ebfn nh\u01b0 if trong JavaScript, c\u00e2u l\u1ec7nh else, if else ho\u1eb7c else\u2026if. H\u1ecdc c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh \u0111i\u1ec1u ki\u1ec7n ngay.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/if-trong-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/09\/if-trong-JavaScript-vippro.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/09\/if-trong-JavaScript-vippro.jpg","width":1500,"height":790,"caption":"if trong JavaScript - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/if-trong-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh if trong JavaScript chi ti\u1ebft"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/f4cd1226846e0258c664e170d3e52d20","name":"Uyen Ngo","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/ngo-thieu-my-uyen-author-e1709880420317-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/ngo-thieu-my-uyen-author-e1709880420317-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/ngo-thieu-my-uyen-author-e1709880420317-100x100.jpg","caption":"Uyen Ngo"},"url":"https:\/\/itviec.com\/blog\/author\/uyen-ngo\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/78942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/207"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=78942"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/78942\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/79222"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=78942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=78942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=78942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}