Phương thức console.log() dùng để ghi thông điệp ra console trình duyệt.
Ví dụ
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>Ví dụ console.log()</h1> <button class="Btn">NHẤN VÀO ĐÂY</button> <h3>Nhấn nút để xem output trong console (F12)</h3> <script> let test = { a:22, b:'HELLO', c:44, } console.log(test); console.log('HELLO WORLD'); </script> </body> </html>
Kết quả
Mở DevTools (F12) > Console sẽ thấy object test và chuỗi "HELLO WORLD".