{"id":84687,"date":"2025-02-28T10:43:23","date_gmt":"2025-02-28T03:43:23","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=84687"},"modified":"2025-02-28T10:43:23","modified_gmt":"2025-02-28T03:43:23","slug":"cau-hoi-phong-van-javascript","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/","title":{"rendered":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 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\/cau-hoi-phong-van-javascript\/#JavaScript_Developer_lam_cong_viec_gi\" >JavaScript Developer l\u00e0m c\u00f4ng vi\u1ec7c g\u00ec?<\/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\/cau-hoi-phong-van-javascript\/#Cau_hoi_phong_van_JavaScript_danh_cho_nguoi_moi_bat_dau\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript d\u00e0nh cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u<\/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\/cau-hoi-phong-van-javascript\/#Cau_hoi_phong_van_JavaScript_danh_cho_nguoi_co_kinh_nghiem\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript d\u00e0nh cho ng\u01b0\u1eddi c\u00f3 kinh nghi\u1ec7m<\/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\/cau-hoi-phong-van-javascript\/#Cau_hoi_phong_van_JavaScript_thuc_hanh\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript th\u1ef1c h\u00e0nh<\/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\/cau-hoi-phong-van-javascript\/#Tong_ket_cau_hoi_phong_van_JavaScript\" >T\u1ed5ng k\u1ebft c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript\u00a0<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>M\u1ed9t bu\u1ed5i ph\u1ecfng v\u1ea5n JavaScript k\u1ef9 thu\u1eadt l\u00e0 m\u1ed9t ph\u1ea7n quan tr\u1ecdng gi\u00fap \u0111\u00e1nh gi\u00e1 ki\u1ebfn th\u1ee9c v\u00e0 k\u1ef9 n\u0103ng l\u1eadp tr\u00ecnh vi\u00ean. \u0110\u1ec3 c\u00f3 bu\u1ed5i ph\u1ecfng v\u1ea5n th\u00e0nh c\u00f4ng, b\u1ea1n s\u1ebd c\u1ea7n n\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m c\u01a1 b\u1ea3n c\u0169ng nh\u01b0 k\u1ef9 n\u0103ng th\u1ef1c h\u00e0nh nhu\u1ea7n nhuy\u1ec5n. H\u00e3y c\u00f9ng c\u1eadp nh\u1eadt danh s\u00e1ch nh\u1eefng c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript ph\u1ed5 bi\u1ebfn k\u00e8m theo c\u00e2u tr\u1ea3 l\u1eddi chi ti\u1ebft \u0111\u1ec3 n\u1eafm ch\u1eafc ki\u1ebfn th\u1ee9c cho bu\u1ed5i ph\u1ecfng v\u1ea5n s\u1eafp t\u1edbi!<\/strong><\/em><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ecdc b\u00e0i vi\u1ebft sau \u0111\u00e2y \u0111\u1ec3 c\u00f3 g\u00f3c nh\u00ecn chi ti\u1ebft h\u01a1n v\u1ec1:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript d\u00e0nh cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript d\u00e0nh cho ng\u01b0\u1eddi \u0111\u00e3 c\u00f3 kinh nghi\u1ec7m<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript v\u1ec1 k\u1ef9 n\u0103ng th\u1ef1c h\u00e0nh<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"JavaScript_Developer_lam_cong_viec_gi\"><\/span><b>JavaScript Developer l\u00e0m c\u00f4ng vi\u1ec7c g\u00ec?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">JavaScript Developer s\u1ebd l\u00e0 m\u1ed9t l\u1eadp tr\u00ecnh vi\u00ean chuy\u00ean t\u1ea1o c\u00e1c \u1ee9ng d\u1ee5ng web \u0111\u1ed9ng v\u00e0 c\u00f3 s\u1ef1 t\u01b0\u01a1ng t\u00e1c b\u1eb1ng ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh JavaScript. Nh\u1eefng ng\u01b0\u1eddi ph\u1ee5 tr\u00e1ch ph\u00e1t tri\u1ec3n web hi\u1ec7n \u0111\u1ea1i, t\u1ea1o ra m\u00e3 ph\u1ee9c t\u1ea1p h\u1ed7 tr\u1ee3 giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng v\u00e0 n\u00e2ng cao tr\u1ea3i nghi\u1ec7m c\u1ee7a ng\u01b0\u1eddi d\u00f9ng tr\u00ean nhi\u1ec1u n\u1ec1n t\u1ea3ng k\u1ef9 thu\u1eadt s\u1ed1 kh\u00e1c nhau.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t s\u1ed1 JavaScript Developers s\u1ebd ch\u1ecbu tr\u00e1ch nhi\u1ec7m x\u00e2y d\u1ef1ng v\u00e0 duy tr\u00ec to\u00e0n b\u1ed9 trang web, trong khi m\u1ed9t s\u1ed1 v\u1ecb tr\u00ed s\u1ebd t\u1eadp trung v\u00e0o c\u00e1c th\u00e0nh ph\u1ea7n tr\u1ef1c quan giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng v\u00e0 \u0111\u1ea3m b\u1ea3o k\u1ebft n\u1ed1i c\u1ee7a ch\u00fang v\u1edbi c\u00e1c d\u1ecbch v\u1ee5 ph\u1ee5 tr\u1ee3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Khi s\u1eed d\u1ee5ng nhu\u1ea7n nhuy\u1ec5n JavaScript c\u00f9ng v\u1edbi c\u00e1c k\u1ef9 n\u0103ng li\u00ean quan v\u1ec1 l\u0129nh v\u1ef1c IT, b\u1ea1n s\u1ebd c\u00f3 nhi\u1ec1u c\u01a1 h\u1ed9i ph\u00e1t tri\u1ec3n \u1edf nhi\u1ec1u v\u1ecb tr\u00ed kh\u00e1c nhau, ch\u1eb3ng h\u1ea1n nh\u01b0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Front-End Developer<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Back-End Developer\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Full-stack Developer<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">ReactJS Developer<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Freelance JavaScript Developer<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">B\u00ean c\u1ea1nh ki\u1ebfn th\u1ee9c v\u1ec1 JavaScript, b\u1ea1n c\u0169ng s\u1ebd c\u1ea7n n\u1eafm v\u1eefng v\u1ec1<\/span> <strong><a href=\"https:\/\/itviec.com\/blog\/html-la-gi\/\" target=\"_blank\" rel=\"noopener\">HTML<\/a><\/strong><span style=\"font-weight: 400;\"> v\u00e0<\/span> <strong><a href=\"https:\/\/itviec.com\/blog\/css-la-gi\/\" target=\"_blank\" rel=\"noopener\">CSS<\/a><\/strong><span style=\"font-weight: 400;\">, l\u00e0m quen v\u1edbi c\u00e1c ph\u1ea7n m\u1ec1m li\u00ean quan nh\u01b0<\/span> <strong><a href=\"https:\/\/itviec.com\/blog\/nodejs-la-gi\/\" target=\"_blank\" rel=\"noopener\">Node.js<\/a><\/strong><span style=\"font-weight: 400;\">, Express.js,<\/span> <strong><a href=\"https:\/\/itviec.com\/blog\/mongodb-la-gi\/\" target=\"_blank\" rel=\"noopener\">MongoDB<\/a><\/strong><span style=\"font-weight: 400;\">,&#8230; \u0111\u1ec3 \u0111\u01b0\u1ee3c cung c\u1ea5p n\u1ec1n t\u1ea3ng v\u1eefng ch\u1eafc ph\u00e1t tri\u1ec3n to\u00e0n di\u1ec7n c\u1ea3 v\u1ec1 Front-End v\u00e0 Back-End trong l\u0129nh v\u1ef1c IT.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Theo<\/span> <strong><a href=\"https:\/\/itviec.com\/bao-cao\/luong-it-va-thi-truong-tuyen-dung-it-vietnam\" target=\"_blank\" rel=\"noopener\">B\u00e1o c\u00e1o L\u01b0\u01a1ng v\u00e0 Th\u1ecb tr\u01b0\u1eddng Tuy\u1ec3n d\u1ee5ng IT t\u1ea1i Vi\u1ec7t Nam 2024 \u2013 2025<\/a><\/strong><span style=\"font-weight: 400;\"> m\u1edbi nh\u1ea5t do ITviec th\u1ef1c hi\u1ec7n, m\u1ee9c l\u01b0\u01a1ng trung v\u1ecb c\u1ee7a c\u00e1c v\u1ecb tr\u00ed li\u00ean quan v\u1ec1 JavaScript nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td rowspan=\"2\"><strong>S\u1ed1 n\u0103m kinh nghi\u1ec7m<\/strong><\/td>\n<td colspan=\"3\"><span style=\"font-weight: 400;\"><strong>M\u1ee9c l\u01b0\u01a1ng trung v\u1ecb<\/strong> (\u0111\u01a1n v\u1ecb: VND\/ th\u00e1ng)<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Front-End Developer<\/b><\/td>\n<td><b>Full-stack Developer<\/b><\/td>\n<td><b>Back-End Developer<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&lt; 1 n\u0103m<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\/A<\/span><\/td>\n<td><span style=\"font-weight: 400;\">14.700.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\/A<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1-2 n\u0103m<\/span><\/td>\n<td><span style=\"font-weight: 400;\">16.100.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">16.650.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">19.200.000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3-4 n\u0103m<\/span><\/td>\n<td><span style=\"font-weight: 400;\">23.300.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">29.900.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">26.000.000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">5-8 n\u0103m<\/span><\/td>\n<td><span style=\"font-weight: 400;\">34.950.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">39.700.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">45.300.000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&gt;8 n\u0103m\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">50.950.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">50.000.000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">54.500.000<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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\u1edbng ph\u00e1t tri\u1ec3n c\u1ee7a JavaScript Developer<\/i><\/a><\/strong><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_JavaScript_danh_cho_nguoi_moi_bat_dau\"><\/span><b> C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript d\u00e0nh cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>B\u1ea1n hi\u1ec3u g\u00ec v\u1ec1 Data Type trong JavaScript?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ki\u1ec3u d\u1eef li\u1ec7u (data types) c\u1ee7a JavaScript \u0111\u01b0\u1ee3c chia th\u00e0nh 2 ph\u1ea7n l\u00e0 ki\u1ec3u d\u1eef li\u1ec7u nguy\u00ean th\u1ee7y (primitive type) v\u00e0 ki\u1ec3u d\u1eef li\u1ec7u kh\u00f4ng nguy\u00ean th\u1ee7y (non-primitive type).\u00a0<\/span><\/p>\n<h4><b>Primitive Type<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00e1c ki\u1ec3u d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh tr\u01b0\u1edbc do ng\u00f4n ng\u1eef JavaScript cung c\u1ea5p, hay c\u00f2n \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 ki\u1ec3u d\u1eef li\u1ec7u t\u00edch h\u1ee3p. Bao g\u1ed3m s\u1ed1 (number), chu\u1ed7i (string), boolean, symbols, undefined, null.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">typeof \"ITviec\" \/\/ Tr\u1ea3 v\u1ec1 chu\u1ed7i<\/span>\r\n\r\n<span style=\"font-weight: 400;\">typeof 3.14 \/\/ Tr\u1ea3 v\u1ec1 s\u1ed1<\/span>\r\n\r\n<span style=\"font-weight: 400;\">typeof true \/\/ Tr\u1ea3 v\u1ec1 boolean<\/span>\r\n\r\n<span style=\"font-weight: 400;\">typeof 234567890123456789012345678901234567890n \/\/ Tr\u1ea3 v\u1ec1 bigint<\/span>\r\n\r\n<span style=\"font-weight: 400;\">typeof undefined \/\/ Tr\u1ea3 v\u1ec1 undefined<\/span>\r\n\r\n<span style=\"font-weight: 400;\">typeof null \/\/ Tr\u1ea3 v\u1ec1 object<\/span>\r\n\r\n<span style=\"font-weight: 400;\">typeof Symbol('symbol') \/\/ Tr\u1ea3 v\u1ec1 symbol<\/span><\/pre>\n<h4><b>Non-Primitive Type<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">L\u01b0u tr\u1eef m\u1ed9t d\u1eef li\u1ec7u duy nh\u1ea5t. \u0110\u1ec3 l\u01b0u tr\u1eef nhi\u1ec1u gi\u00e1 tr\u1ecb ph\u1ee9c t\u1ea1p, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ki\u1ec3u d\u1eef li\u1ec7u kh\u00f4ng nguy\u00ean th\u1ee7y. Th\u01b0\u1eddng bao g\u1ed3m object, function v\u00e0 array.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var obj1 = {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0x:\u00a0 43,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0y:\u00a0 \"ITviec\",<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0z: function(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0return this.x;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">var array1 = [5, \"ITviec\", true, 4.1];\u00a0<\/span><\/pre>\n<h3><b>Java vs JavaScript c\u00f3 g\u00ec kh\u00e1c bi\u1ec7t?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Java l\u00e0 ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng (object), trong khi JavaScript l\u00e0 ng\u00f4n ng\u1eef script ph\u00eda m\u00e1y kh\u00e1ch. C\u1ee5 th\u1ec3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Java: <\/b><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng v\u00e0 c\u00f3 n\u1ec1n t\u1ea3ng m\u00e1y \u1ea3o cho ph\u00e9p b\u1ea1n t\u1ea1o c\u00e1c ch\u01b0\u01a1ng tr\u00ecnh bi\u00ean d\u1ecbch ch\u1ea1y \u0111\u01b0\u1ee3c tr\u00ean h\u1ea7u h\u1ebft c\u00e1c n\u1ec1n t\u1ea3ng.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>JavaScript:<\/b><span style=\"font-weight: 400;\"> \u0110\u00e2y l\u00e0 ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh \u0111\u1ec3 ph\u00e1t tri\u1ec3n c\u00e1c trang web c\u00f3 t\u00ednh t\u01b0\u01a1ng t\u00e1c. JavaScript c\u00f3 th\u1ec3 cho ph\u00e9p b\u1ea1n ch\u00e8n v\u0103n b\u1ea3n \u0111\u1ed9ng v\u00e0o c\u00e1c th\u00e0nh ph\u1ea7n HTML, gi\u00fap trang web c\u00f3 t\u00ednh t\u01b0\u01a1ng t\u00e1c v\u00e0 sinh \u0111\u1ed9ng h\u01a1n.\u00a0<\/span><\/li>\n<\/ul>\n<h3><b>Gi\u1ea3i th\u00edch Hosting trong JavaScript?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Hosting l\u00e0 h\u00e0nh vi m\u1eb7c \u0111\u1ecbnh c\u1ee7a JavaScript, trong \u0111\u00f3 t\u1ea5t c\u1ea3 khai b\u00e1o bi\u1ebfn v\u00e0 h\u00e0m \u0111\u01b0\u1ee3c di chuy\u1ec3n l\u00ean tr\u00ean c\u00f9ng. \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 b\u1ea5t k\u1ef3 bi\u1ebfn v\u00e0 h\u00e0m \u0111\u01b0\u1ee3c khai b\u00e1o \u1edf \u0111\u00e2u, ch\u00fang \u0111\u1ec1u \u0111\u01b0\u1ee3c di chuy\u1ec3n l\u00ean v\u1ecb tr\u00ed tr\u00ean c\u00f9ng c\u1ee7a ph\u1ea1m vi (scope). Ph\u1ea1m vi c\u00f3 th\u1ec3 l\u00e0 c\u1ee5c b\u1ed9 (local) ho\u1eb7c to\u00e0n c\u1ee5c (global).<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">hoistedVariable = 3;<\/span>\r\n<span style=\"font-weight: 400;\">console.log(hoistedVariable); \/\/ <\/span><i><span style=\"font-weight: 400;\">\u0111\u1ea7u ra 3 ngay c\u1ea3 khi bi\u1ebfn \u0111\u01b0\u1ee3c khai b\u00e1o sau khi n\u00f3 \u0111\u01b0\u1ee3c kh\u1edfi t\u1ea1o<\/span><\/i>\r\n<span style=\"font-weight: 400;\">var hoistedVariable;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function doSomething(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0x = 33;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0console.log(x);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var x;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra, b\u1ea1n n\u00ean l\u01b0u \u00fd m\u1ed9t s\u1ed1 \u0111i\u1ec1u khi s\u1eed d\u1ee5ng hosting nh\u01b0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Hosting ch\u1ec9 \u00e1p d\u1ee5ng cho khai b\u00e1o var, kh\u00f4ng \u00e1p d\u1ee5ng cho let v\u00e0 const.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Khai b\u00e1o h\u00e0m \u0111\u01b0\u1ee3c hosting ho\u00e0n to\u00e0n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ch\u1ec9 khai b\u00e1o \u0111\u01b0\u1ee3c hosting, kh\u00f4ng ph\u1ea3i ph\u00e9p g\u00e1n.<\/span><\/li>\n<\/ul>\n<h3><b>B\u1ea1n hi\u1ec3u g\u00ec v\u1ec1 NaN trong JavaScript?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Thu\u1ed9c t\u00ednh NaN bi\u1ec3u th\u1ecb cho gi\u00e1 tr\u1ecb \u201cNot-a-Number\u201d, ngh\u0129a l\u00e0 gi\u00e1 tr\u1ecb kh\u00f4ng ph\u1ea3i l\u00e0 s\u1ed1 h\u1ee3p l\u1ec7. Ki\u1ec3u c\u1ee7a NaN s\u1ebd tr\u1ea3 v\u1ec1 l\u00e0 m\u1ed9t con s\u1ed1 (number). \u0110\u1ec3 ki\u1ec3m tra xem gi\u00e1 tr\u1ecb c\u00f3 ph\u1ea3i l\u00e0 NaN hay kh\u00f4ng, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng h\u00e0m isNaN(), c\u1ee5 th\u1ec3 nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">isNaN(\"Hello\")\u00a0 \/\/ Tr\u1ea3 v\u1ec1 true<\/span>\r\n\r\n<span style=\"font-weight: 400;\">isNaN(345) \u00a0 \/\/\u00a0 Tr\u1ea3 v\u1ec1 false<\/span>\r\n\r\n<span style=\"font-weight: 400;\">isNaN('1')\u00a0 \/\/\u00a0 Tr\u1ea3 v\u1ec1 false, v\u00ec \u201c1\u201d \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ed5i th\u00e0nh s\u1ed1 (number), k\u1ebft qu\u1ea3 l\u00e0 0 (m\u1ed9t s\u1ed1)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">isNaN(true) \/\/ Tr\u1ea3 v\u1ec1 false, v\u00ec true \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ed5i th\u00e0nh ki\u1ec3u s\u1ed1 (number), k\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1 l\u00e0 1 (m\u1ed9t con s\u1ed1).<\/span>\r\n\r\n<span style=\"font-weight: 400;\">isNaN(false) \/\/ Tr\u1ea3 v\u1ec1 false<\/span>\r\n\r\n<span style=\"font-weight: 400;\">isNaN(undefined) \/\/ Tr\u1ea3 v\u1ec1 true<\/span><\/pre>\n<h3><b>Gi\u1ea3i th\u00edch Closures trong JavaScript<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Closures l\u00e0 kh\u1ea3 n\u0103ng c\u1ee7a m\u1ed9t h\u00e0m \u0111\u1ec3 ghi nh\u1edb c\u00e1c bi\u1ebfn v\u00e0 h\u00e0m \u0111\u01b0\u1ee3c khai b\u00e1o trong ph\u1ea1m vi b\u00ean ngo\u00e0i c\u1ee7a n\u00f3.\u00a0<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var Person = function(pName){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var name = pName;\r\n<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0this.getName = function(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return name;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">var person = new Person(\"Neelesh\");<\/span>\r\n<span style=\"font-weight: 400;\">console.log(person.getName());<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">T\u00ecm hi\u1ec3u v\u1ec1 closures qua v\u00ed d\u1ee5 nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function randomFunc(){<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0var obj1 = {name:\"ITviec\"};<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0return function(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0console.log(obj1.name + \" is \"+ \"awesome\");\u00a0<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">var initialiseClosure = randomFunc();\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">initialiseClosure();<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">H\u00e0m randomFunc() \u0111\u01b0\u1ee3c th\u1ef1c thi v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t h\u00e0m khi g\u00e1n n\u00f3 cho m\u1ed9t bi\u1ebfn.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var initialiseClosure = randomFunc();<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Sau \u0111\u00f3, h\u00e0m tr\u1ea3 v\u1ec1 s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi khi g\u1ecdi initialiseClosure.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">initialiseClosure();<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">D\u00f2ng m\u00e3 tr\u00ean cho ra k\u1ebft qu\u1ea3 \u201cITviec is awesome\u201d v\u00e0 \u0111i\u1ec1u n\u00e0y c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n \u0111\u01b0\u1ee3c nh\u1edd t\u00ednh n\u0103ng \u0111\u00f3ng.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">console.log(obj1.name + \" is \"+ \"awesome\");<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Khi h\u00e0m randomFunc() ch\u1ea1y, h\u00e0m s\u1ebd tr\u1ea3 v\u1ec1 \u0111ang s\u1eed d\u1ee5ng bi\u1ebfn obj1 b\u00ean trong n\u00f3. Do \u0111\u00f3, randomFunc(), thay v\u00ec h\u1ee7y gi\u00e1 tr\u1ecb c\u1ee7a obj1 sau khi th\u1ef1c thi, s\u1ebd l\u01b0u gi\u00e1 tr\u1ecb trong b\u1ed9 nh\u1edb \u0111\u1ec3 tham chi\u1ebfu th\u00eam.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 l\u00fd do t\u1ea1i sao h\u00e0m tr\u1ea3 v\u1ec1 c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng bi\u1ebfn \u0111\u01b0\u1ee3c khai b\u00e1o trong ph\u1ea1m vi b\u00ean ngo\u00e0i ngay c\u1ea3 sau khi h\u00e0m \u0111\u00e3 \u0111\u01b0\u1ee3c th\u1ef1c thi.Kh\u1ea3 n\u0103ng l\u01b0u tr\u1eef bi\u1ebfn \u0111\u1ec3 tham chi\u1ebfu th\u00eam c\u1ee7a h\u00e0m n\u00e0y ngay c\u1ea3 sau khi h\u00e0m \u0111\u00e3 \u0111\u01b0\u1ee3c th\u1ef1c thi \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 Closure.<\/span><\/p>\n<h3><b>B\u1ea1n hi\u1ec3u g\u00ec v\u1ec1 client-side v\u00e0 server-side trong JavaScript?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">JavaScript ph\u00eda m\u00e1y kh\u00e1ch (client-side) bao g\u1ed3m hai ph\u1ea7n, m\u1ed9t ng\u00f4n ng\u1eef c\u01a1 b\u1ea3n v\u00e0 c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh tr\u01b0\u1edbc \u0111\u1ec3 th\u1ef1c hi\u1ec7n JavaScript trong tr\u00ecnh duy\u1ec7t. JavaScript cho m\u00e1y kh\u00e1ch \u0111\u01b0\u1ee3c t\u1ef1 \u0111\u1ed9ng \u0111\u01b0a v\u00e0o c\u00e1c trang HTML. Khi ch\u1ea1y, tr\u00ecnh duy\u1ec7t hi\u1ec3u \u0111\u01b0\u1ee3c t\u1eadp l\u1ec7nh n\u00e0y.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Trong khi \u0111\u00f3, JavaScript ph\u00eda m\u00e1y ch\u1ee7 (server-side), bao g\u1ed3m vi\u1ec7c th\u1ef1c thi m\u00e3 JavaScript tr\u00ean m\u00e1y ch\u1ee7 \u0111\u1ec3 \u0111\u00e1p \u1ee9ng c\u00e1c y\u00eau c\u1ea7u c\u1ee7a m\u00e1y kh\u00e1ch. N\u00f3 x\u1eed l\u00fd c\u00e1c y\u00eau c\u1ea7u n\u00e0y v\u00e0 cung c\u1ea5p ph\u1ea3n h\u1ed3i c\u00f3 li\u00ean quan cho m\u00e1y kh\u00e1ch, c\u00f3 th\u1ec3 bao g\u1ed3m JavaScript ph\u00eda m\u00e1y kh\u00e1ch \u0111\u1ec3 th\u1ef1c thi ti\u1ebfp theo trong tr\u00ecnh duy\u1ec7t.<\/span><\/p>\n<h3><b>DOM l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">DOM l\u00e0 vi\u1ebft t\u1eaft c\u1ee7a Document Object Model, ngh\u0129a l\u00e0 giao di\u1ec7n l\u1eadp tr\u00ecnh cho c\u00e1c t\u00e0i li\u1ec7u HTML v\u00e0 XML. Khi tr\u00ecnh duy\u1ec7t c\u1ed1 g\u1eafng hi\u1ec3n th\u1ecb m\u1ed9t t\u00e0i li\u1ec7u HTML, n\u00f3 s\u1ebd t\u1ea1o ra m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng d\u1ef1a tr\u00ean t\u00e0i li\u1ec7u HTML \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 DOM. Khi s\u1eed d\u1ee5ng DOM, b\u1ea1n c\u00f3 th\u1ec3 thao t\u00e1c ho\u1eb7c thay \u0111\u1ed5i nhi\u1ec1u th\u00e0nh ph\u1ea7n kh\u00e1c nhau b\u00ean trong t\u00e0i li\u1ec7u HTML.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 v\u1ec1 c\u00e1ch m\u00e3 HTML \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ed5i th\u00e0nh DOM:<\/span><\/p>\n<pre>&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n&lt;title&gt;\r\nDOM example\r\n&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n&lt;p id=\"para1\"&gt;Hello&lt;\/p&gt;\r\n&lt;p id=\"para2\"&gt;Hey&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/pre>\n<h3><b>T\u1ea1i sao s\u1eed d\u1ee5ng debugger trong JavaScript?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Debugger (tr\u00ecnh g\u1ee1 l\u1ed7i) trong tr\u00ecnh duy\u1ec7t ph\u1ea3i \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t \u0111\u1ec3 g\u1ee1 l\u1ed7i m\u00e3. Tr\u00ecnh g\u1ee1 l\u1ed7i t\u00edch h\u1ee3p c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c b\u1eadt v\u00e0 t\u1eaft \u0111\u1ec3 y\u00eau c\u1ea7u ng\u01b0\u1eddi d\u00f9ng b\u00e1o c\u00e1o l\u1ed7i. Ph\u1ea7n c\u00f2n l\u1ea1i c\u1ee7a m\u00e3 ph\u1ea3i \u0111\u01b0\u1ee3c d\u1eebng th\u1ef1c thi tr\u01b0\u1edbc khi chuy\u1ec3n sang d\u00f2ng ti\u1ebfp theo trong khi g\u1ee1 l\u1ed7i.<\/span><\/p>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa \u201c==\u201d v\u00e0 \u201c===\u201d trong JavaScript<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u201c==\u201d v\u00e0 \u201c===\u201d \u0111\u1ec1u l\u00e0 to\u00e1n t\u1eed so s\u00e1nh. S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa 2 to\u00e1n t\u1eed n\u00e0y l\u00e0 \u201c==\u201d \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 so s\u00e1nh c\u00e1c gi\u00e1 tr\u1ecb trong khi \u201c===\u201d \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 so s\u00e1nh c\u1ea3 gi\u00e1 tr\u1ecb v\u00e0 ki\u1ec3u.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var x = 2;<\/span>\r\n<span style=\"font-weight: 400;\">var y = \"2\";<\/span>\r\n\r\n<span style=\"font-weight: 400;\">(x == y)\u00a0 \/\/ <\/span><i><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb true c\u1ee7a c\u1ea3 x v\u00e0 y \u0111\u1ec1u gi\u1ed1ng nhau<\/span><\/i>\r\n<span style=\"font-weight: 400;\">(x === y) \/\/ <\/span><i><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb false v\u00ec ki\u1ec3u c\u1ee7a x l\u00e0 \"s\u1ed1\" v\u00e0 ki\u1ec3u c\u1ee7a y l\u00e0 \"chu\u1ed7i\"<\/span><\/i><\/pre>\n<h3><b>Gi\u1ea3i th\u00edch kh\u00e1i ni\u1ec7m Prototype (nguy\u00ean m\u1eabu) trong JavaScript<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">T\u1ea5t c\u1ea3 c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng JavaScript \u0111\u1ec1u k\u1ebf th\u1eeba c\u00e1c thu\u1ed9c t\u00ednh t\u1eeb m\u1ed9t nguy\u00ean m\u1eabu.\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng Date k\u1ebf th\u1eeba c\u00e1c thu\u1ed9c t\u00ednh t\u1eeb nguy\u00ean m\u1eabu Date<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng Math k\u1ebf th\u1eeba c\u00e1c thu\u1ed9c t\u00ednh t\u1eeb nguy\u00ean m\u1eabu Math<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng Array k\u1ebf th\u1eeba c\u00e1c thu\u1ed9c t\u00ednh t\u1eeb nguy\u00ean m\u1eabu Array.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Tr\u00ean c\u00f9ng c\u1ee7a chu\u1ed7i l\u00e0 Object.prototype. M\u1ed7i nguy\u00ean m\u1eabu \u0111\u1ec1u k\u1ebf th\u1eeba c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c t\u1eeb Object.prototype.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">M\u1ed9t nguy\u00ean m\u1eabu l\u00e0 b\u1ea3n thi\u1ebft k\u1ebf c\u1ee7a m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng. Prototype cho ph\u00e9p s\u1eed d\u1ee5ng c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c tr\u00ean m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng ngay c\u1ea3 khi c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c \u0111\u00f3 kh\u00f4ng t\u1ed3n t\u1ea1i tr\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng hi\u1ec7n t\u1ea1i.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var arr = [];<\/span>\r\n<span style=\"font-weight: 400;\">arr.push(2);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">console.log(arr);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111o\u1ea1n m\u00e3 tr\u00ean, kh\u00f4ng \u0111\u1ecbnh ngh\u0129a b\u1ea5t k\u1ef3 thu\u1ed9c t\u00ednh ho\u1eb7c ph\u01b0\u01a1ng th\u1ee9c n\u00e0o \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 push tr\u00ean array nh\u01b0ng JavaScript kh\u00f4ng \u0111\u01b0a ra l\u1ed7i.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">L\u00fd do l\u00e0 s\u1eed d\u1ee5ng c\u00e1c nguy\u00ean m\u1eabu c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng m\u1ea3ng k\u1ebf th\u1eeba c\u00e1c thu\u1ed9c t\u00ednh t\u1eeb nguy\u00ean m\u1eabu M\u1ea3ng. JavaScript th\u1ea5y r\u1eb1ng ph\u01b0\u01a1ng th\u1ee9c push kh\u00f4ng t\u1ed3n t\u1ea1i tr\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng m\u1ea3ng hi\u1ec7n t\u1ea1i v\u00e0 do \u0111\u00f3, t\u00ecm ki\u1ebfm ph\u01b0\u01a1ng th\u1ee9c push b\u00ean trong nguy\u00ean m\u1eabu M\u1ea3ng v\u00e0 t\u00ecm th\u1ea5y ph\u01b0\u01a1ng th\u1ee9c.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_JavaScript_danh_cho_nguoi_co_kinh_nghiem\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript d\u00e0nh cho ng\u01b0\u1eddi c\u00f3 kinh nghi\u1ec7m<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>H\u00e0m b\u1eadc cao (Higher-order Function) trong JavaScript l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m ho\u1ea1t \u0111\u1ed9ng tr\u00ean c\u00e1c h\u00e0m kh\u00e1c, b\u1eb1ng c\u00e1ch l\u1ea5y ch\u00fang l\u00e0m \u0111\u1ed1i s\u1ed1 ho\u1eb7c tr\u1ea3 v\u1ec1 ch\u00fang, \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 c\u00e1c h\u00e0m b\u1eadc cao. L\u00e0 k\u1ebft qu\u1ea3 c\u1ee7a c\u00e1c h\u00e0m h\u1ea1ng nh\u1ea5t trong JavaScript.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t s\u1ed1 v\u00ed d\u1ee5 v\u1ec1 h\u00e0m b\u1eadc cao c\u00f3 th\u1ec3 k\u1ec3 \u0111\u1ebfn nh\u01b0:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function higherOrder(fn) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0fn();<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">higherOrder(function() { console.log(\"ITviec\") });\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function higherOrder2() {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return function() {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return \"Do something\";<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">var x = higherOrder2();<\/span>\r\n<span style=\"font-weight: 400;\">x()<\/span><\/pre>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 Scope v\u00e0 Scope Chain trong JavaScript<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ph\u1ea1m vi (Scope) trong JavaScript x\u00e1c \u0111\u1ecbnh kh\u1ea3 n\u0103ng truy c\u1eadp c\u1ee7a c\u00e1c bi\u1ebfn v\u00e0 h\u00e0m t\u1ea1i c\u00e1c ph\u1ea7n kh\u00e1c nhau c\u1ee7a m\u00e3. Ph\u1ea1m vi s\u1ebd cho bi\u1ebft t\u1ea1i m\u1ed9t ph\u1ea7n nh\u1ea5t \u0111\u1ecbnh c\u1ee7a m\u00e3, nh\u1eefng bi\u1ebfn v\u00e0 h\u00e0m n\u00e0o ch\u00fang ta c\u00f3 th\u1ec3 ho\u1eb7c kh\u00f4ng th\u1ec3 truy c\u1eadp.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00f3 ba lo\u1ea1i ph\u1ea1m vi trong JS bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ph\u1ea1m vi to\u00e0n c\u1ee5c (global scope): <\/b><span style=\"font-weight: 400;\">C\u00e1c bi\u1ebfn ho\u1eb7c h\u00e0m \u0111\u01b0\u1ee3c khai b\u00e1o trong kh\u00f4ng gian t\u00ean to\u00e0n c\u1ee5c c\u00f3 ph\u1ea1m vi to\u00e0n c\u1ee5c, ngh\u0129a l\u00e0 t\u1ea5t c\u1ea3 c\u00e1c bi\u1ebfn v\u00e0 h\u00e0m c\u00f3 ph\u1ea1m vi to\u00e0n c\u1ee5c \u0111\u1ec1u c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c truy c\u1eadp t\u1eeb b\u1ea5t k\u1ef3 \u0111\u00e2u b\u00ean trong m\u00e3.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ph\u1ea1m vi c\u1ee5c b\u1ed9 (function scope)<\/b><span style=\"font-weight: 400;\">: T\u1ea5t c\u1ea3 c\u00e1c bi\u1ebfn v\u00e0 h\u00e0m \u0111\u01b0\u1ee3c khai b\u00e1o b\u00ean trong m\u1ed9t h\u00e0m \u0111\u1ec1u c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c truy c\u1eadp t\u1eeb b\u00ean trong h\u00e0m ch\u1ee9 kh\u00f4ng ph\u1ea3i b\u00ean ngo\u00e0i h\u00e0m.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ph\u1ea1m vi kh\u1ed1i (block scope):<\/b><span style=\"font-weight: 400;\"> Cho bi\u1ebft b\u1ea5t k\u1ef3 bi\u1ebfn n\u00e0o \u0111\u01b0\u1ee3c khai b\u00e1o b\u00ean trong kh\u1ed1i { }, ch\u1ec9 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c truy c\u1eadp b\u00ean trong kh\u1ed1i \u0111\u00f3 v\u00e0 kh\u00f4ng th\u1ec3 \u0111\u01b0\u1ee3c truy c\u1eadp b\u00ean ngo\u00e0i kh\u1ed1i \u0111\u00f3. C\u00e1c bi\u1ebfn \u0111\u01b0\u1ee3c tri\u1ec3n khai b\u1eb1ng let v\u00e0 const s\u1ebd c\u00f3 ph\u1ea1m vi kh\u1ed1i, bi\u1ebfn khai b\u00e1o b\u1eb1ng var kh\u00f4ng c\u00f3 ph\u1ea1m vi kh\u1ed1i.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Scope Chain s\u1ebd s\u1eed d\u1ee5ng scope (ph\u1ea1m vi) \u0111\u1ec3 t\u00ecm bi\u1ebfn, v\u00ed d\u1ee5 nh\u01b0:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var y = 24;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function favFunction(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var x = 667;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var anotherFavFunction = function(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0console.log(x);\u00a0<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var yetAnotherFavFunction = function(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0console.log(y);\u00a0<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0anotherFavFunction();<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0yetAnotherFavFunction();<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">favFunction();<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u1ede v\u00ed d\u1ee5 tr\u00ean, n\u1ebfu JavaScript kh\u00f4ng t\u00ecm th\u1ea5y bi\u1ebfn trong ph\u1ea1m vi c\u1ee5c b\u1ed9, n\u00f3 s\u1ebd c\u1ed1 g\u1eafng ki\u1ec3m tra bi\u1ebfn trong ph\u1ea1m vi b\u00ean ngo\u00e0i. N\u1ebfu bi\u1ebfn kh\u00f4ng t\u1ed3n t\u1ea1i trong ph\u1ea1m vi b\u00ean ngo\u00e0i, n\u00f3 s\u1ebd c\u1ed1 g\u1eafng t\u00ecm bi\u1ebfn trong ph\u1ea1m vi to\u00e0n c\u1ee5c.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">N\u1ebfu bi\u1ebfn c\u0169ng kh\u00f4ng \u0111\u01b0\u1ee3c t\u00ecm th\u1ea5y trong kh\u00f4ng gian to\u00e0n c\u1ee5c, m\u1ed9t l\u1ed7i tham chi\u1ebfu s\u1ebd \u0111\u01b0\u1ee3c \u0111\u01b0a ra.<\/span><\/p>\n<h3><b>L\u1ee3i th\u1ebf c\u1ee7a vi\u1ec7c s\u1eed d\u1ee5ng External JavaScript l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">External JavaScript l\u00e0 m\u00e3 JavaScript (script) \u0111\u01b0\u1ee3c vi\u1ebft trong m\u1ed9t t\u1ec7p ri\u00eang c\u00f3 ph\u1ea7n m\u1edf r\u1ed9ng .js, sau \u0111\u00f3 li\u00ean k\u1ebft t\u1ec7p \u0111\u00f3 b\u00ean trong ph\u1ea7n t\u1eed &lt;head&gt; ho\u1eb7c &lt;body&gt; c\u1ee7a t\u1ec7p HTML n\u01a1i m\u00e3 s\u1ebd \u0111\u01b0\u1ee3c \u0111\u1eb7t.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t s\u1ed1 l\u1ee3i th\u1ebf c\u1ee7a External JavaScript c\u00f3 th\u1ec3 k\u1ec3 \u0111\u1ebfn nh\u01b0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Cho ph\u00e9p c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean thi\u1ebft l\u1eadp tr\u1ef1c ti\u1ebfp tr\u00ean c\u00e1c t\u1ec7p HTML v\u00e0 JavaScript.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 s\u1eed d\u1ee5ng l\u1ea1i m\u00e3.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Kh\u1ea3 n\u0103ng \u0111\u1ecdc m\u00e3 r\u1ea5t \u0111\u01a1n gi\u1ea3n.<\/span><\/li>\n<\/ul>\n<h3><b>C\u00e1c lo\u1ea1i l\u1ed7i trong JavaScript<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3 2 lo\u1ea1i l\u1ed7i trong JavaScript:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>L\u1ed7i c\u00fa ph\u00e1p (Syntax error):<\/b><span style=\"font-weight: 400;\"> L\u1ed7i c\u00fa ph\u00e1p l\u00e0 l\u1ed7i ho\u1eb7c l\u1ed7i ch\u00ednh t\u1ea3 trong m\u00e3 khi\u1ebfn ch\u01b0\u01a1ng tr\u00ecnh kh\u00f4ng th\u1ef1c thi \u0111\u01b0\u1ee3c ho\u1eb7c d\u1eebng ch\u1ea1y gi\u1eefa ch\u1eebng.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>L\u1ed7i logic (logic error):<\/b><span style=\"font-weight: 400;\"> X\u1ea3y ra khi c\u00fa ph\u00e1p \u0111\u00fang nh\u01b0ng logic ho\u1eb7c ch\u01b0\u01a1ng tr\u00ecnh kh\u00f4ng ch\u00ednh x\u00e1c. \u0110\u00f4i khi, nh\u1eefng l\u1ed7i n\u00e0y kh\u00f3 s\u1eeda h\u01a1n c\u00e1c v\u1ea5n \u0111\u1ec1 c\u00fa ph\u00e1p v\u00ec c\u00e1c \u1ee9ng d\u1ee5ng kh\u00f4ng hi\u1ec3n th\u1ecb t\u00edn hi\u1ec7u l\u1ed7i cho l\u1ed7i logic.<\/span><\/li>\n<\/ul>\n<h3><b>Memoization trong JavaScript l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Memorization (ghi nh\u1edb) l\u00e0 m\u1ed9t d\u1ea1ng l\u01b0u tr\u1eef \u0111\u1ec7m trong \u0111\u00f3 gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1 c\u1ee7a m\u1ed9t h\u00e0m \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef \u0111\u1ec7m d\u1ef1a tr\u00ean c\u00e1c tham s\u1ed1 c\u1ee7a n\u00f3. N\u1ebfu tham s\u1ed1 c\u1ee7a h\u00e0m \u0111\u00f3 kh\u00f4ng thay \u0111\u1ed5i, phi\u00ean b\u1ea3n l\u01b0u tr\u1eef \u0111\u1ec7m c\u1ee7a h\u00e0m s\u1ebd \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/ Fibonacci kh\u00f4ng s\u1eed d\u1ee5ng memoization<\/span>\r\n<span style=\"font-weight: 400;\">function fibonacci(n) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0if (n &lt;= 1) return n;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return fibonacci(n - 1) + fibonacci(n - 2);<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Fibonacci s\u1eed d\u1ee5ng memoization<\/span>\r\n<span style=\"font-weight: 400;\">function memoizedFibonacci() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0const cache = {};<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0return function fib(n) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\/\/ Ki\u1ec3m tra cache<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0if (n in cache) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0return cache[n];<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0if (n &lt;= 1) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0return n;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\/\/ L\u01b0u k\u1ebft qu\u1ea3 v\u00e0o cache<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0cache[n] = fib(n - 1) + fib(n - 2);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return cache[n];<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">const memFib = memoizedFibonacci();<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ So s\u00e1nh hi\u1ec7u n\u0103ng<\/span>\r\n<span style=\"font-weight: 400;\">console.time('Kh\u00f4ng memoization');<\/span>\r\n<span style=\"font-weight: 400;\">console.log(fibonacci(40));\u00a0 \u00a0 \/\/ Ch\u1eadm<\/span>\r\n<span style=\"font-weight: 400;\">console.timeEnd('Kh\u00f4ng memoization');<\/span>\r\n\r\n<span style=\"font-weight: 400;\">console.time('C\u00f3 memoization');<\/span>\r\n<span style=\"font-weight: 400;\">console.log(memFib(40)); \u00a0 \u00a0 \u00a0 \/\/ Nhanh h\u01a1n nhi\u1ec1u<\/span>\r\n<span style=\"font-weight: 400;\">console.timeEnd('C\u00f3 memoization');<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Qua v\u00ed d\u1ee5 tr\u00ean, c\u00f3 th\u1ec3 th\u1ea5y \u0111\u01b0\u1ee3c l\u1ee3i \u00edch c\u1ee7a memoization:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Tr\u00e1nh t\u00ednh to\u00e1n l\u1eb7p l\u1ea1i v\u1edbi c\u00f9ng input.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">T\u0103ng hi\u1ec7u su\u1ea5t \u0111\u00e1ng k\u1ec3 v\u1edbi c\u00e1c ph\u00e9p t\u00ednh ph\u1ee9c t\u1ea1p.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1ed5i dung l\u01b0\u1ee3ng b\u1ed9 nh\u1edb l\u1ea5y t\u1ed1c \u0111\u1ed9 x\u1eed l\u00fd.<\/span><\/li>\n<\/ul>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa Prototypal v\u00e0 Classic inheritance?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">L\u1eadp tr\u00ecnh vi\u00ean x\u00e2y d\u1ef1ng c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng, l\u00e0 c\u00e1c bi\u1ec3u di\u1ec5n c\u1ee7a th\u1ef1c th\u1ec3 th\u1eddi gian th\u1ef1c, trong l\u1eadp tr\u00ecnh OOP truy\u1ec1n th\u1ed1ng. C\u00e1c l\u1edbp v\u00e0 \u0111\u1ed1i t\u01b0\u1ee3ng l\u00e0 hai lo\u1ea1i tr\u1eebu t\u01b0\u1ee3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t l\u1edbp l\u00e0 m\u1ed9t kh\u00e1i qu\u00e1t h\u00f3a c\u1ee7a m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng, trong khi m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng l\u00e0 m\u1ed9t tr\u1eebu t\u01b0\u1ee3ng h\u00f3a c\u1ee7a m\u1ed9t v\u1eadt th\u1ef1c t\u1ebf. V\u00ed d\u1ee5, m\u1ed9t chi\u1ebfc xe l\u00e0 m\u1ed9t chuy\u00ean m\u00f4n h\u00f3a c\u1ee7a m\u1ed9t chi\u1ebfc xe h\u01a1i. Do \u0111\u00f3, \u00f4 t\u00f4 (l\u1edbp) \u0111\u01b0\u1ee3c k\u1ebf th\u1eeba t\u1eeb c\u00e1c ph\u01b0\u01a1ng ti\u1ec7n (\u0111\u1ed1i t\u01b0\u1ee3ng).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">K\u1ebf th\u1eeba c\u1ed5 \u0111i\u1ec3n (Classic inheritance) kh\u00e1c v\u1edbi k\u1ebf th\u1eeba nguy\u00ean m\u1eabu (Prototypal Inheritance) \u1edf ch\u1ed7 k\u1ebf th\u1eeba c\u1ed5 \u0111i\u1ec3n b\u1ecb gi\u1edbi h\u1ea1n trong c\u00e1c l\u1edbp k\u1ebf th\u1eeba t\u1eeb c\u00e1c l\u1edbp c\u00f2n l\u1ea1i, nh\u01b0ng k\u1ebf th\u1eeba nguy\u00ean m\u1eabu cho ph\u00e9p b\u1ea5t k\u1ef3 \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0o \u0111\u01b0\u1ee3c sao ch\u00e9p th\u00f4ng qua ph\u01b0\u01a1ng ph\u00e1p li\u00ean k\u1ebft \u0111\u1ed1i t\u01b0\u1ee3ng. M\u1eb7c d\u00f9 \u0111i s\u00e2u v\u00e0o qu\u00e1 nhi\u1ec1u chi ti\u1ebft c\u1ee5 th\u1ec3, v\u1ec1 c\u01a1 b\u1ea3n, m\u1ed9t nguy\u00ean m\u1eabu \u0111\u00f3ng vai tr\u00f2 nh\u01b0 m\u1ed9t khu\u00f4n m\u1eabu cho c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng kh\u00e1c, cho d\u00f9 ch\u00fang c\u00f3 m\u1edf r\u1ed9ng \u0111\u1ed1i t\u01b0\u1ee3ng cha hay kh\u00f4ng.<\/span><\/p>\n<h3><b>H\u00e0m g\u1ecdi l\u1ea1i (callback function) l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Callback (h\u00e0m g\u1ecdi l\u1ea1i) l\u00e0 m\u1ed9t h\u00e0m s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi sau khi m\u1ed9t h\u00e0m kh\u00e1c \u0111\u01b0\u1ee3c th\u1ef1c thi. Trong JavaScript, c\u00e1c h\u00e0m c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng l\u00e0m \u0111\u1ed1i s\u1ed1 c\u1ee7a m\u1ed9t h\u00e0m kh\u00e1c, c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 b\u1edfi m\u1ed9t h\u00e0m kh\u00e1c ho\u1eb7c \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng l\u00e0m thu\u1ed9c t\u00ednh c\u1ee7a m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function divideByHalf(sum){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0console.log(Math.floor(sum \/ 2));<\/span>\r\n<span style=\"font-weight: 400;\">}\r\n<\/span>\r\n<span style=\"font-weight: 400;\">function multiplyBy2(sum){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0console.log(sum * 2);<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function operationOnSum(num1,num2,operation){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var sum = num1 + num2;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0operation(sum);<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">operationOnSum(3, 3, divideByHalf); \/\/ K\u1ebft qu\u1ea3 hi\u1ec3n th\u1ecb: 3<\/span>\r\n\r\n<span style=\"font-weight: 400;\">operationOnSum(5, 5, multiplyBy2); \/\/ K\u1ebft qu\u1ea3 hi\u1ec3n th\u1ecb: 20<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111o\u1ea1n m\u00e3 tr\u00ean \u0111ang th\u1ef1c hi\u1ec7n c\u00e1c ph\u00e9p to\u00e1n tr\u00ean t\u1ed5ng c\u1ee7a hai s\u1ed1. Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">H\u00e0m operationOnSum l\u1ea5y 3 \u0111\u1ed1i s\u1ed1, s\u1ed1 \u0111\u1ea7u ti\u00ean, s\u1ed1 th\u1ee9 hai v\u00e0 ph\u00e9p to\u00e1n s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n tr\u00ean t\u1ed5ng c\u1ee7a ch\u00fang (g\u1ecdi l\u1ea1i).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u1ea3 hai h\u00e0m divideByHalf v\u00e0 multiplyBy2 \u0111\u1ec1u \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng l\u00e0m h\u00e0m g\u1ecdi l\u1ea1i trong \u0111o\u1ea1n m\u00e3 tr\u00ean.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m g\u1ecdi l\u1ea1i n\u00e0y s\u1ebd ch\u1ec9 \u0111\u01b0\u1ee3c th\u1ef1c thi sau khi h\u00e0m operationOnSum \u0111\u01b0\u1ee3c th\u1ef1c thi.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Do \u0111\u00f3, h\u00e0m g\u1ecdi l\u1ea1i l\u00e0 h\u00e0m s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi sau khi m\u1ed9t h\u00e0m kh\u00e1c \u0111\u01b0\u1ee3c th\u1ef1c thi.<\/span><\/p>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa Async\/Await v\u00e0 Generators \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111\u1ea1t \u0111\u01b0\u1ee3c ch\u1ee9c n\u0103ng t\u01b0\u01a1ng t\u1ef1<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m Generator \u0111\u01b0\u1ee3c ch\u1ea1y theo tr\u00ecnh t\u1ea1o yield by yield, ngh\u0129a l\u00e0 t\u1eebng \u0111\u1ea7u ra m\u1ed9t, trong khi c\u00e1c h\u00e0m Async-await \u0111\u01b0\u1ee3c th\u1ef1c thi tu\u1ea7n t\u1ef1.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Async\/await cung c\u1ea5p m\u1ed9t tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng nh\u1ea5t \u0111\u1ecbnh \u0111\u1ec3 Generator d\u1ec5 th\u1ef1c thi h\u01a1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 \u0111\u1ea7u ra c\u1ee7a h\u00e0m Generator lu\u00f4n l\u00e0 gi\u00e1 tr\u1ecb: X, done: Boolean, nh\u01b0ng gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1 c\u1ee7a h\u00e0m Async lu\u00f4n l\u00e0 m\u1ed9t s\u1ef1 \u0111\u1ea3m b\u1ea3o ho\u1eb7c \u0111\u01b0a ra l\u1ed7i.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">\/\/ Generator<\/span>\r\n<span style=\"font-weight: 400;\">function* numberGenerator() {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0yield 1;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0yield 2;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Async\/Await<\/span>\r\n<span style=\"font-weight: 400;\">async function getData() {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0const result = await fetch('\/api\/data');<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return result.json();<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h3><b>B\u1ea1n hi\u1ec3u g\u00ec v\u1ec1 recursion trong ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Recursion l\u00e0 m\u1ed9t k\u1ef9 thu\u1eadt l\u1eb7p l\u1ea1i m\u1ed9t ho\u1ea1t \u0111\u1ed9ng b\u1eb1ng c\u00e1ch g\u1ecdi ch\u00ednh h\u00e0m \u0111\u00f3 nhi\u1ec1u l\u1ea7n cho \u0111\u1ebfn khi \u0111\u1ea1t \u0111\u01b0\u1ee3c k\u1ebft qu\u1ea3.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function add(number) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0if (number &lt;= 0) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return 0;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0} else {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return number + add(number - 1);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">add(3) =&gt; 3 + add(2)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a03 + 2 + add(1)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a03 + 2 + 1 + add(0)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a03 + 2 + 1 + 0 = 6<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ch\u1eb3ng h\u1ea1n nh\u01b0 v\u00ed d\u1ee5 sau \u0111\u00e2y s\u1ebd t\u00ednh t\u1ed5ng c\u1ee7a t\u1ea5t c\u1ea3 c\u00e1c ph\u1ea7n t\u1eed trong m\u1ed9t m\u1ea3ng b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng recursion.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function computeSum(arr){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0if(arr.length === 1){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return arr[0];<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0else{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return arr.pop() + computeSum(arr);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">computeSum([7, 8, 9, 99]); \/\/ Tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 123<\/span><\/pre>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 WeakSet trong JavaScript<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong JavaScript, Set l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c ph\u1ea7n t\u1eed duy nh\u1ea5t v\u00e0 \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp. Gi\u1ed1ng nh\u01b0 Set, WeakSet c\u0169ng l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c ph\u1ea7n t\u1eed duy nh\u1ea5t v\u00e0 \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp v\u1edbi m\u1ed9t s\u1ed1 \u0111i\u1ec3m kh\u00e1c bi\u1ec7t nh\u01b0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Weakset ch\u1ec9 ch\u1ee9a c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng (object) v\u00e0 kh\u00f4ng c\u00f3 lo\u1ea1i n\u00e0o kh\u00e1c.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">M\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng b\u00ean trong WeakSet \u0111\u01b0\u1ee3c tham chi\u1ebfu y\u1ebfu. \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 n\u1ebfu \u0111\u1ed1i t\u01b0\u1ee3ng b\u00ean trong weakset kh\u00f4ng c\u00f3 tham chi\u1ebfu, n\u00f3 s\u1ebd \u0111\u01b0\u1ee3c thu gom r\u00e1c.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Kh\u00f4ng gi\u1ed1ng nh\u01b0 Set, WeakSet ch\u1ec9 c\u00f3 ba ph\u01b0\u01a1ng th\u1ee9c, add() , delete() v\u00e0 has().<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">const newSet = new Set([4, 5, 6, 7]);<\/span>\r\n<span style=\"font-weight: 400;\">console.log(newSet);\/\/ \u0110\u1ea7u ra: Set {4,5,6,7}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">const newSet2 = new WeakSet([3, 4, 5]); <\/span>\r\n<span style=\"font-weight: 400;\">let obj1 = {message:\"Hello world\"};<\/span>\r\n<span style=\"font-weight: 400;\">const newSet3 = new WeakSet([obj1]);<\/span>\r\n<span style=\"font-weight: 400;\">console.log(newSet3.has(obj1)); \/\/ true<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_JavaScript_thuc_hanh\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript th\u1ef1c h\u00e0nh<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>Tri\u1ec3n khai m\u1ed9t h\u00e0m tr\u1ea3 v\u1ec1 m\u1ed9t m\u1ea3ng \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt v\u1edbi r ph\u00e9p quay ph\u1ea3i tr\u00ean m\u1ed9t m\u1ea3ng s\u1ed1 nguy\u00ean a.<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 cho m\u1ea3ng sau [2,3,4,5,7]. <\/span><span style=\"font-weight: 400;\">H\u00e3y th\u1ef1c hi\u1ec7n 3 ph\u00e9p quay ph\u1ea3i. Ph\u00e9p quay \u0111\u1ea7u ti\u00ean: [7,2,3,4,5], Ph\u00e9p quay th\u1ee9 hai: [5,7,2,3,4] v\u00e0 Ph\u00e9p quay th\u1ee9 ba: [4,5,7,2,3]<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function rotateRight(arr,rotations){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0if(rotations == 0) return arr;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0for(let i = 0; i &lt; rotations;i++){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0let element = arr.pop();<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0arr.unshift(element);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return arr;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">rotateRight([2, 3, 4, 5, 7], 3); \/\/ Return [4,5,7,2,3]<\/span>\r\n<span style=\"font-weight: 400;\">rotateRight([44, 1, 22, 111], 5); \/\/ Returns [111,44,1,22]\u00a0\u00a0\u00a0<\/span><\/pre>\n<h3><b>Vi\u1ebft h\u00e0m th\u1ef1c hi\u1ec7n t\u00ecm ki\u1ebfm nh\u1ecb ph\u00e2n tr\u00ean m\u1ed9t m\u1ea3ng \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp.<\/b><\/h3>\n<pre><span style=\"font-weight: 400;\">function binarySearch(arr,value,startPos,endPos){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0if(startPos &gt; endPos) return -1;\r\n<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0let middleIndex = Math.floor((startPos + endPos) \/ 2);\r\n<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0if(arr[middleIndex] === value) return middleIndex;<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0else if(arr[middleIndex] &gt; value){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return binarySearch(arr,value,startPos,middleIndex-1);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0else{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return binarySearch(arr,value,middleIndex+1,endPos);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}\u00a0<\/span><\/pre>\n<h3><b>Cho \u0111o\u1ea1n m\u00e3 sau, h\u00e3y d\u1ef1 \u0111o\u00e1n k\u1ebft qu\u1ea3 hi\u1ec3n th\u1ecb c\u1ee7a \u0111o\u1ea1n m\u00e3<\/b><\/h3>\n<pre><span style=\"font-weight: 400;\">var x = 23;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">(function(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var x = 43;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0(function random(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0x++;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0console.log(x);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0var x = 21;<\/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;\">K\u1ebft qu\u1ea3 hi\u1ec3n th\u1ecb s\u1ebd l\u00e0 NaN, H\u00e0m random() c\u00f3 ph\u1ea1m vi ch\u1ee9c n\u0103ng v\u00ec x \u0111\u01b0\u1ee3c khai b\u00e1o v\u00e0 \u0111\u01b0\u1ee3c \u0111\u01b0a l\u00ean trong ph\u1ea1m vi ch\u1ee9c n\u0103ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 vi\u1ebft l\u1ea1i h\u00e0m theo c\u00e1ch nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function random(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var x;\u00a0<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0x++; \/\/ x kh\u00f4ng ph\u1ea3i l\u00e0 s\u1ed1 v\u00ec n\u00f3 ch\u01b0a \u0111\u01b0\u1ee3c kh\u1edfi t\u1ea1o<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0console.log(x); \/\/ Outputs NaN<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0x = 21; \/\/ Kh\u1edfi t\u1ea1o x<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h3><b>Cho \u0111o\u1ea1n m\u00e3 sau, h\u00e3y d\u1ef1 \u0111o\u00e1n k\u1ebft qu\u1ea3 hi\u1ec3n th\u1ecb c\u1ee7a \u0111o\u1ea1n m\u00e3<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">M\u00e3 s\u1ed1 1:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">(function(a){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return (function(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0console.log(a);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0a = 23;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0})()<\/span>\r\n<span style=\"font-weight: 400;\">})(45);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">M\u00e3 s\u1ed1 2:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/ M\u1ed7i l\u1ea7n bigFunc \u0111\u01b0\u1ee3c g\u1ecdi, m\u1ed9t m\u1ea3ng c\u00f3 k\u00edch th\u01b0\u1edbc 700 s\u1ebd \u0111\u01b0\u1ee3c t\u1ea1o ra,<\/span>\r\n<span style=\"font-weight: 400;\">\/\/ S\u1eeda \u0111\u1ed5i m\u00e3 \u0111\u1ec3 kh\u00f4ng t\u1ea1o ra c\u00f9ng m\u1ed9t m\u1ea3ng nhi\u1ec1u l\u1ea7n<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function bigFunc(element){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0let newArray = new Array(700).fill('\u2665');<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return newArray[element];<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">console.log(bigFunc(599)); \/\/ M\u1ea3ng \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o<\/span>\r\n<span style=\"font-weight: 400;\">console.log(bigFunc(670)); \/\/ M\u1ea3ng \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">M\u00e3 s\u1ed1 3:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/ \u0110o\u1ea1n m\u00e3 sau \u0111\u00e2y xu\u1ea5t ra 2 v\u00e0 2 sau khi \u0111\u1ee3i m\u1ed9t gi\u00e2y<\/span>\r\n<span style=\"font-weight: 400;\">\/\/ S\u1eeda \u0111\u1ed5i \u0111o\u1ea1n m\u00e3 \u0111\u1ec3 xu\u1ea5t ra 0 v\u00e0 1 sau m\u1ed9t gi\u00e2y.<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function randomFunc(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0for(var i = 0; i &lt; 2; i++){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0setTimeout(()=&gt; console.log(i),1000);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">randomFunc();<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Theo 3 \u0111o\u1ea1n tr\u00ean, ta c\u00f3 \u0111\u00e1p \u00e1n nh\u01b0 sau:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110o\u1ea1n m\u00e3 s\u1ed1 1 k\u1ebft qu\u1ea3 l\u00e0 45. M\u1eb7c d\u00f9 a \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong h\u00e0m b\u00ean ngo\u00e0i nh\u01b0ng do t\u00ednh \u0111\u00f3ng n\u00ean c\u00e1c h\u00e0m b\u00ean trong v\u1eabn c\u00f3 th\u1ec3 truy c\u1eadp v\u00e0o n\u00f3.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u1ede \u0111o\u1ea1n m\u00e3 s\u1ed1 2, c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eeda \u0111\u1ed5i b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng closures.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">function bigFunc(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0let newArray = new Array(700).fill('\u2665');<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return (element) =&gt; newArray[element];<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">let getElement = bigFunc();<\/span>\r\n<span style=\"font-weight: 400;\">getElement(599);<\/span>\r\n<span style=\"font-weight: 400;\">getElement(670);\u00a0\u00a0<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u1ede \u0111o\u1ea1n m\u00e3 s\u1ed1 3, c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eeda \u0111\u1ed5i b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng t\u1eeb kh\u00f3a let ho\u1eb7c closures.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">function randomFunc(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0for(let i = 0; i &lt; 2; i++){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0setTimeout(()=&gt; console.log(i),1000);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">randomFunc();\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">function randomFunc(){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0for(var i = 0; i &lt; 2; i++){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0(function(i){<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0setTimeout(()=&gt;console.log(i),1000);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0})(i);<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">randomFunc();<\/span><\/pre>\n<h3><b>Vi\u1ebft m\u1ed9t \u0111o\u1ea1n m\u00e3 theo y\u00eau c\u1ea7u n\u1ebfu hai chu\u1ed7i l\u00e0 ch\u1eef \u0111\u1ea3o ng\u01b0\u1ee3c c\u1ee7a nhau th\u00ec tr\u1ea3 v\u1ec1 true.<\/b><\/h3>\n<pre><span style=\"font-weight: 400;\">var firstWord = \"ITviec\";<\/span>\r\n<span style=\"font-weight: 400;\">var secondWord = \"Blog\";<\/span>\r\n\r\n<span style=\"font-weight: 400;\">isAnagram(firstWord, secondWord ); <\/span><i><span style=\"font-weight: 400;\">\/\/ true<\/span><\/i>\r\n\r\n<span style=\"font-weight: 400;\">function isAnagram(firstWord, secondWord ) {<\/span>\r\n<i><span style=\"font-weight: 400;\"> \u00a0\/\/\u0110\u1ed5i c\u1ea3 hai t\u1eeb sang ch\u1eef th\u01b0\u1eddng \u0111\u1ec3 kh\u00f4ng ph\u00e2n bi\u1ec7t ch\u1eef hoa ch\u1eef th\u01b0\u1eddng.<\/span><\/i>\r\n<span style=\"font-weight: 400;\"> \u00a0var a = one.toLowerCase();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0var b = two.toLowerCase();<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ S\u1eafp x\u1ebfp c\u00e1c chu\u1ed7i, sau \u0111\u00f3 k\u1ebft h\u1ee3p m\u1ea3ng th\u00e0nh m\u1ed9t chu\u1ed7i. Ki\u1ec3m tra k\u1ebft qu\u1ea3.<\/span><\/i>\r\n<span style=\"font-weight: 400;\"> \u00a0a = a.split(\"\").sort().join(\"\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0b = b.split(\"\").sort().join(\"\");<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0return a === b;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h3><b>Vi\u1ebft \u0111o\u1ea1n m\u00e3 \u0111\u1ec3 t\u00ecm nguy\u00ean \u00e2m<\/b><\/h3>\n<pre><span style=\"font-weight: 400;\">const findVowels = str =&gt; {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0let count = 0<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0const vowels = ['a', 'e', 'i', 'o', 'u']<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0for(let char of str.toLowerCase()) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0if(vowels.includes(char)) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0count++<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return count<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_cau_hoi_phong_van_JavaScript\"><\/span><b>T\u1ed5ng k\u1ebft c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Nh\u01b0 v\u1eady, ITviec \u0111\u00e3 t\u1ed5ng h\u1ee3p chi ti\u1ebft 25+ <\/span>c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript <span style=\"font-weight: 400;\">theo nhi\u1ec1u tr\u00ecnh \u0111\u1ed9 v\u00e0 kinh nghi\u1ec7m kh\u00e1c nhau. Vi\u1ec7c chu\u1ea9n b\u1ecb c\u00e2u h\u1ecfi k\u1ef9 c\u00e0ng s\u1ebd gi\u00fap b\u1ea1n d\u1ec5 d\u00e0ng ghi \u0111i\u1ec3m tr\u01b0\u1edbc nh\u00e0 tuy\u1ec3n d\u1ee5ng. H\u00e3y ti\u1ebfp t\u1ee5c r\u00e8n luy\u1ec7n v\u00e0 th\u1ef1c h\u00e0nh \u0111\u1ec3 n\u00e2ng cao k\u1ef9 n\u0103ng JavaScript, s\u1eb5n s\u00e0ng cho c\u01a1 h\u1ed9i ngh\u1ec1 nghi\u1ec7p s\u1eafp t\u1edbi nh\u00e9!<\/span><i><\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>M\u1ed9t bu\u1ed5i ph\u1ecfng v\u1ea5n JavaScript k\u1ef9 thu\u1eadt l\u00e0 m\u1ed9t ph\u1ea7n quan tr\u1ecdng gi\u00fap \u0111\u00e1nh gi\u00e1 ki\u1ebfn th\u1ee9c v\u00e0 k\u1ef9 n\u0103ng l\u1eadp tr\u00ecnh vi\u00ean. \u0110\u1ec3 c\u00f3 bu\u1ed5i ph\u1ecfng v\u1ea5n th\u00e0nh c\u00f4ng, b\u1ea1n s\u1ebd c\u1ea7n n\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m c\u01a1 b\u1ea3n c\u0169ng nh\u01b0 k\u1ef9 n\u0103ng th\u1ef1c h\u00e0nh nhu\u1ea7n nhuy\u1ec5n. H\u00e3y c\u00f9ng c\u1eadp nh\u1eadt danh s\u00e1ch nh\u1eefng [&hellip;]<\/p>\n","protected":false},"author":207,"featured_media":84741,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109,105],"tags":[],"class_list":["post-84687","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it","category-phong-van-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh - ITviec Blog<\/title>\n<meta name=\"description\" content=\"T\u1ed5ng h\u1ee3p 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript ph\u1ed5 bi\u1ebfn d\u00e0nh cho t\u1eeb fresher cho \u0111\u1ebfn chuy\u00ean gia, t\u1eeb l\u00fd thuy\u1ebft \u0111\u1ebfn th\u1ef1c h\u00e0nh, k\u00e8m tr\u1ea3 l\u1eddi chi ti\u1ebft.\" \/>\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\/cau-hoi-phong-van-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh\" \/>\n<meta property=\"og:description\" content=\"M\u1ed9t bu\u1ed5i ph\u1ecfng v\u1ea5n JavaScript k\u1ef9 thu\u1eadt l\u00e0 m\u1ed9t ph\u1ea7n quan tr\u1ecdng gi\u00fap \u0111\u00e1nh gi\u00e1 ki\u1ebfn th\u1ee9c v\u00e0 k\u1ef9 n\u0103ng l\u1eadp tr\u00ecnh vi\u00ean. \u0110\u1ec3 c\u00f3 bu\u1ed5i ph\u1ecfng v\u1ea5n th\u00e0nh c\u00f4ng, b\u1ea1n s\u1ebd\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-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=\"2025-02-28T03:43:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-hoi-phong-van-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=\"18 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh - ITviec Blog","description":"T\u1ed5ng h\u1ee3p 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript ph\u1ed5 bi\u1ebfn d\u00e0nh cho t\u1eeb fresher cho \u0111\u1ebfn chuy\u00ean gia, t\u1eeb l\u00fd thuy\u1ebft \u0111\u1ebfn th\u1ef1c h\u00e0nh, k\u00e8m tr\u1ea3 l\u1eddi chi ti\u1ebft.","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\/cau-hoi-phong-van-javascript\/","og_locale":"vi_VN","og_type":"article","og_title":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh","og_description":"M\u1ed9t bu\u1ed5i ph\u1ecfng v\u1ea5n JavaScript k\u1ef9 thu\u1eadt l\u00e0 m\u1ed9t ph\u1ea7n quan tr\u1ecdng gi\u00fap \u0111\u00e1nh gi\u00e1 ki\u1ebfn th\u1ee9c v\u00e0 k\u1ef9 n\u0103ng l\u1eadp tr\u00ecnh vi\u00ean. \u0110\u1ec3 c\u00f3 bu\u1ed5i ph\u1ecfng v\u1ea5n th\u00e0nh c\u00f4ng, b\u1ea1n s\u1ebd","og_url":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-02-28T03:43:23+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-hoi-phong-van-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":"18 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/"},"author":{"name":"Uyen Ngo","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/f4cd1226846e0258c664e170d3e52d20"},"headline":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh","datePublished":"2025-02-28T03:43:23+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/"},"wordCount":4599,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-hoi-phong-van-javascript-vippro.jpg","articleSection":["Chuy\u00ean m\u00f4n IT","Ph\u1ecfng v\u1ea5n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/","url":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/","name":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-hoi-phong-van-javascript-vippro.jpg","datePublished":"2025-02-28T03:43:23+00:00","description":"T\u1ed5ng h\u1ee3p 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript ph\u1ed5 bi\u1ebfn d\u00e0nh cho t\u1eeb fresher cho \u0111\u1ebfn chuy\u00ean gia, t\u1eeb l\u00fd thuy\u1ebft \u0111\u1ebfn th\u1ef1c h\u00e0nh, k\u00e8m tr\u1ea3 l\u1eddi chi ti\u1ebft.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-javascript\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-hoi-phong-van-javascript-vippro.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-hoi-phong-van-javascript-vippro.jpg","width":1500,"height":790,"caption":"c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n javascript - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-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":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n JavaScript l\u00fd thuy\u1ebft v\u00e0 th\u1ef1c h\u00e0nh"}]},{"@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\/84687","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=84687"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/84687\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/84741"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=84687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=84687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=84687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}