Open Web Browser Inspect -> console and let’s do some fun:
1
2
3
4
5
6
7
8
| // Error -> a is not define
a;
// Alert Massage
alert(120);
// Clear the console from inspect
clear()
|
console.log()
console object: entity that has some property and methods.
1
2
3
4
5
6
7
8
9
| // See all methods
>>> console
```[]
Method: `log()`
:
```js
// One of the method is log
console.log(); // required to pass an argument
|
Print Numbers :
1
2
| // print numbers
console.log(100);
|
Print String :
1
2
| // print string of characters
console.log('Hello World!');
|
Multi Print :
1
2
| // Multiple Print
console.log(20, 'Hello', true);
|
Using Variable :
1
2
3
| // define variable
const x = 100;
console.log(x);
|
console.error()
1
2
| // Error Message
console.error('Alert Message');
|
console
for developer use not for user.
console.warn()
1
2
| // Warning
console.warn('Warning Message');
|
console.table()
Tables: used for objects (key value pair) like dictionary in python.
1
2
| console.table({name: 'Mohd Irfan', email: 'irfan@gmail.com'});
// It wrapped into a table
|
console.group()
1
2
3
4
5
| console.group('Simple Group');
console.log('Line no. 1');
console.log('Line no. 2');
console.log('Line no. 3');
console.groupEnd();
|
Using Style
1
2
3
4
| // Style
const styles = 'padding: 10px; background-colo: white; color: green;';
// To apply style add %c at begging
console.log('%cHello World!', styles)
|