FrontEnd web
Published in

FrontEnd web

Javascript Console API?

Easy ways to Learn Basic to Advance All Console Web API with Demo

Javascript Console API By Rajdeep Singh
Javascript Console API.
Console.< web API Name here >Exmple:
console.log();
console.clear();

Demo:

Web Console API

  1. assert
  2. clear
  3. count
  4. countReset
  5. debug
  6. dir
  7. dirxml
  8. error
  9. group
  10. groupCollapsed
  11. groupEnd
  12. info
  13. log
  14. markTimeline
  15. profile
  16. profileEnd
  17. table
  18. time
  19. timeEnd
  20. timeLog
  21. timeStamp
  22. trace
  23. warm
  24. memory

Opening the console

Chrome:

1. Window/Linux:

Ctrl + Shift + J  
Ctrl + Shift + I //then click to console tab

2. Mac Os

Cmd + Opt + J

Firefox

1. Window/Linux

Ctrl + Shift + K
Ctrl + Shift + I // then click to console tab

2. Mac Os

Cmd + Opt + K

3. Edge and Internet Explorer

4. Opera

Ctrl + Shift + I // Then click on the console tab

Console

window.console
window.console
Check the result in the web console

Compatibility:

if(typeof window.console !== 'undifined'){
console.log('this working'); // some code here
}
if(window.console){
console.log('this is working') // some code here
}

Formatting console output

Specifier:

  1. %s: formatting the value as a string.
  2. %i or %d: formatting the value as an integer.
  3. %f: formatting the value as a floating-point value.
  4. %o: formatting the value as an expandable DOM element.
  5. %O: formatting the value as an expandable javascript object.
  6. %c: Applies CSS style rules to the output string as specified by the second parameter.
console.log("Hello, My name is  %s. You've called log %d. Floting value %f and javscript object  %O", "Rajdeep Singh",  1, 6.7 ,{test:'testing', num:34});console.warn("Hello, My name is  %s. You've called warn %d. Floting value %f and javscript object  %O", "Rajdeep Singh",  1, 5.7, {test:'testing', num:34});console.info("Hello, My name is  %s. You've called info %d. Floting value %f and javscript object  %O", "Rajdeep Singh",  1, 6.75, {test:'testing', num:34});console.error("Hello, My name is  %s. You've called error %d. Floting value %f and javscript object  %O", "Rajdeep Singh",  1, 6.7455, {test:'testing', num:34});

formatting Example %s, %f, %O

formatting Example %s, %f, %O console web API IN JS
formatting Example %s, %f, %O

Formatting Example With CSS style

console.log("%cHello, My name is %s do working .", "color:red", "Rajdeep Singh" );console.warn("%cHello, My name is %s . working", " color:green", "Rajdeep Singh");
Formatting with %c CSS style in console web API
Formatting with CSS

Formatting Example with %o

console.log("Hello, My name is  %s. You've called log. %o", "Rajdeep Singh",  document.body);console.warn("Hello, My name is  %s. You've called log. %o", "Rajdeep Singh",  document.body);console.error("Hello, My name is  %s. You've called log. %o", "Rajdeep Singh",  document.body);console.info("Hello, My name is  %s. You've called log. %o", "Rajdeep Singh",  document.body);
formatting Example with %o in formatting with console web API
formatting Example with %o

Note

// console.warn(" %c Hello, My name is %s do notwork .", "Rajdeep Singh", "color:green" ); // No Working Seuence matter

Assert

Note

console.assert(expression , message)expression = Boolen Value (true or false)
message = your custom message
Exampleconsole.assert(false , 'this working');
console.assert(true , 'this is not working');

clear

console.clear()
console.clear() by web console Api
console.clear()
preserve Log IN chrome web dev tool with web console API
preserve to log in to the Chrome dev tool

Count

console.count( label here )Exmpleconsole.count(); //default 
console.count("test"); // custom label

countReset()

console.countReset( label here );
Exmple:
console.countReset(); // default
console.countReset("test"); // reset counter base on label
console.countReset('test2'); // label not be same than not work

log

console.log()
Exmple
console.log('rajdeep');
console.log(" my name is %s %s Exmple by formating log ", "rajdeep", "singh"); // formating console
look like your console with colour

Note:

debug

Note:

console.debug();Exmple
console.debug('rajdeep singh');
console.debug({});
console.debug([]);

warn:

console.warn();Example
console.warn('testing');

info

console.info();Example
console.info('testing');

error

console.error();Example
console.error('testing');

dir

Note:

console.dir()Example
console.dir( document.body, " console.dir");

dirxml

console.dirxml();Example
console.dirxml( document.body, " console.dirxml");

Difference between log(), dirxml() and dir()

  1. log() , dirxml() both some work. but dir() shows different stuff.
  2. Javascript very weird language.
const counting = {   one: 'one',   two: 'two',   three: 'three' };   console.log(counting); 
console.dir(counting);
console.dirxml(counting);
Difference between log() ,dirxml() and dir()
Difference between log() ,dirxml() and dir()

grouping

console.group('start group'); // label optional
console.log('start test 1');
console.warn('start test 2');
console.error('start test 3');
console.groupEnd('start group')
console.group() and groupEnd() console web api
console.group() and groupEnd()
console.groupCollapsed('start group');  // label optional
console.log('start test 1');
console.warn('start test 2');
console.error('start test 3');
console.groupEnd()
console.groupCollapsed() and console.groupEnd() console web api
console.groupCollapsed() and console.groupEnd()

markTimeline:

Check the issue on GitHub.

Profiling in Js:

Note:

console.profile('testing start')
console.log('testing start');
console.profileEnd('testing start');
console.profile() and console.profileEnd() console web API
console.profile() and console.profileEnd()

More console.profile():

table

console.table();
Exmple:
console.table([ 1,2,3,4,5,6 ]);
console.table([
{
first: 'Rajdeep',
last: 'singh',
id:' 23456'
},
{
first: 'firstName',
last: ' ',
id:'18913',
},
{
first: 'Henri',
last: 'stom',
id:'18783',
}
]);
console.table() console web API
console.table() method

Timing in js :

Note

console.time(label);
Exmple:
console.time("time start");
alert("Click to continue");
console.timeLog("
time start");
alert("click again");
console.timeEnd("answer time");

timeStamp

Note

console.timeStamp() // undefined

trace:

Whats stack?

console.trace()
Exmple:
function traceTest(a, b){
console.trace(" Start Trace");
return a + b;
}
traceTest(23 ,3)
console.trace() web console api
console.trace() in console

Read More about console.trace()

Read More About stack()

memory

  1. jsHeapSizeLimit
  2. totalJSHeapSize
  3. usedJSHeapSize:
console.memory // right syntax
console.memory() // show type Error
Exmple:
console.memory.jsHeapSizeLimit
console.memory web console API
console.memory
console.memory TypeError in web console API
console.memory TypeError

Code For Play

Copy and paste to your editor

Note

Reference:

Conclusion:

Browser compatibility web console API
Browser compatibility by developer.mozilla.org

Contact me:

Thanks for Reading

--

--

FrontendWeb is a platform for writers and readers to read and write a new post about frontend developers, full-stack developers, Web developers, and Computer science. It is an open-source community that join and gathers frontend developers to build and share knowledge with others

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rajdeep singh

JavaScript || Reactjs || Nextjs || Python || Rust || Biotechnology || Bioinformatic || Front-end Developer || Author https://officialrajdeepsingh.dev/