Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
The console object in JavaScript is fundamental piece when we are development ours projects.
‼️ You can go to my Github to find JavaScript examples. ‼️
If we type in our Google Chrome Developer Tools, in the console tag, the word: console you can see that is an object that is inside de global window object:
So you can access the console object from the window object.
window.console
But is not necessary 👓
Let’s get to know her even more:
Print in the console: 🔈
// Printing textconsole.log('Hi!');
// Printing a variableconst PI = Math.PI;console.log(PI);
// Expresionsconsole.log(2 + 4);console.log(`PI value: ${PI}`);
// Comparingconsole.log(null === undefined);console.log(3 > 2);console.log(typeof NaN);console.log(true || false);console.log(true && false);
// Ternary Operatorconsole.log( (3 > 2) ? 'Three!' : 'Two!');
Result: 📍
console.error('Error!');
Result: 📍
console.warn('Be careful')
console.dir(document);console.dir({a: 5});
Result: 📍
function isEqual(x, y) { console.assert( x === y, { "message": "x is not equal than y", "x": x, "y": y });}isEqual(10, 5);
console.clear();
Result: will be the console empty. 📍
Table Output: 📋
const users = [ {name: 'Nick', age: 33}, {name: 'Jessica', age: 23}];console.table(users);
Result: 📍
const users = [10, 20, 30];console.time('performance'); const gThan10 = users.filter(n => n > 10); console.log(gThan10); console.timeEnd('performance');
Result: 📍
console.group('numbers'); console.log(1); console.log(2); console.log(3);console.groupEnd('numbers');
Thank you 😊!
Discovering the Console in JavaScript was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.