Console methods | Console Logs, Errors, Warnings & More | JavaScript Tutorial In Hindi part 1

Опубликовано: 05 Август 2021
на канале: CodeWithKB
64
2

#javascript #console #webdevelopment

Web console
A Web console is a tool which is mainly used to log information associated with a web page like: network requests, javascript, security errors, warnings, CSS etc. It enables us to interact with a web page by executing javascript expression in the contents of the page.


Console object
In javascript, the console is an object which provides access to the browser debugging console. We can open a console in web browser by using: Ctrl + Shift + K for windows and Command + Option + K for Mac. The console object provides us with several different methods, like :


log()
error()
warn()
clear()
time() and timeEnd()
table()
Let’s look at all these methods one by one.

console.log()
Mainly used to log(print) the output to the console. We can put any type inside the log(), be it a string, array, object, boolean etc.

// console.log() method
console.log('abc');
console.log(1);
console.log(true);
console.log(null);
console.log(undefined);
console.log([1, 2, 3, 4]); // array inside log
console.log({a:1, b:2, c:3}); // object inside log

// console.error() method
console.error('This is a simple error');

// console.warn() method
console.warn('This is a warning.');

// console.clear() method
console.clear();


console.time('abc');
let fun = function(){
console.log('fun is running');
}
let fun2 = function(){
console.log('fun2 is running..');
}
fun(); // calling fun();
fun2(); // calling fun2();
console.timeEnd('abc');
console.clear();


// console.table() method
console.table({'a':1, 'b':2});