@ -73,7 +75,14 @@ We can style logging message using css. Copy the following code and paste it on
```js
```js
console.log('%c30 Days Of JavaScript', 'color:green') // log output is green
console.log('%c30 Days Of JavaScript', 'color:green') // log output is green
console.log('%c30 Days%c %cOf%c %cJavaScript%c','color:green','', 'color:red', '', 'color:yellow') // log output green red and yellow text
console.log(
'%c30 Days%c %cOf%c %cJavaScript%c',
'color:green',
'',
'color:red',
'',
'color:yellow'
) // log output green red and yellow text
```
```
### console.warn()
### console.warn()
@ -82,7 +91,9 @@ We use console.warn() to give warning on browser. For instance to inform or war
```js
```js
console.warn('This is a warning')
console.warn('This is a warning')
console.warn('You are using React. Do not touch the DOM. Virtual DOM will take care of handling the DOM!')
console.warn(
'You are using React. Do not touch the DOM. Virtual DOM will take care of handling the DOM!'
)
console.warn('Warning is different from error')
console.warn('Warning is different from error')
```
```
@ -122,7 +133,11 @@ console.table(user)
Check the rest of the examples by copying and paste on the browser console.
Check the rest of the examples by copying and paste on the browser console.
```js
```js
const countries = [['Finland', 'Helsinki'], ['Sweden', 'Stockholm'], ['Norway', 'Oslo']]
const countries = [
['Finland', 'Helsinki'],
['Sweden', 'Stockholm'],
['Norway', 'Oslo']
]
console.table(countries)
console.table(countries)
```
```
@ -161,15 +176,19 @@ console.table(users)
```
```
### console.time()
### console.time()
Starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 10,000 timers running on a given page. When you call console.timeEnd() with the same name, the browser will output the time, in milliseconds, that elapsed since the timer was started.
Starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 10,000 timers running on a given page. When you call console.timeEnd() with the same name, the browser will output the time, in milliseconds, that elapsed since the timer was started.
```js
```js
const countries = [['Finland', 'Helsinki'], ['Sweden', 'Stockholm'], ['Norway', 'Oslo']]
const countries = [
['Finland', 'Helsinki'],
['Sweden', 'Stockholm'],
['Norway', 'Oslo']
]
console.time('Regular for loop')
console.time('Regular for loop')
for (let i = 0; i <countries.length;i++){
for (let i = 0; i <countries.length;i++){
console.log(countries[i][0], countries[i][1])
console.log(countries[i][0], countries[i][1])
}
}
console.timeEnd('Regular for loop')
console.timeEnd('Regular for loop')
@ -222,8 +241,8 @@ console.assert(4 > 3, '4 is greater than 3') // no result
console.assert(3 > 4, '3 is not greater than 4') // Assertion failed: 3 is not greater than 4
console.assert(3 > 4, '3 is not greater than 4') // Assertion failed: 3 is not greater than 4