Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 6005

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 27, 20242024-11-27T02:31:08+00:00 2024-11-27T02:31:08+00:00

JavaScript-30-Day-9

  • 60k

Developer Tools and Console Tricks

demo

ss

On Day-9 of JavaScript-30 we learned a lot of handy console tricks and dev tools to increase our productivity in Web Development.

Lessons Learned:

-Suppose we want to know what is causing a particular thing to happen on a site, you know it's javascript making it happen but not sure exactly which line is responsible.

There is a handy dev tool for us:

Just open the console -> find the element in DOM on which the change is happening -> right click on it -> go to break on -> select attribute modifications

attribute

Next time when you click on the element, it's going to pop a debugger command in. It's a break point for us and it will pause exactly at the line of code that is causing the attribute.
(remove the break point from the same place).

Now we'll see some handy console tricks:

Regular

console.log("Hello"); 
Enter fullscreen mode Exit fullscreen mode

This is our regular console.log() which simply outputs on the console.

regular

Interpolated

console.log("Hello I am a %s string", "💩"); 
Enter fullscreen mode Exit fullscreen mode

interpolation

It interpolates whatever we have passed into the second one into our first message.

Styled

console.log("%c I am some great text", "font-size:20px;background:red;"); 
Enter fullscreen mode Exit fullscreen mode

styled

We can style our text with %c and apply any font-css.

warning!

console.warn("OH NOOOO!"); 
Enter fullscreen mode Exit fullscreen mode

warning

It displays a warning on the console as well as the stack trace as to where the warning came from.

Error:

console.error("Oh Shit!"); 
Enter fullscreen mode Exit fullscreen mode

error

It displays a error message in the console along with the stack trace as to where it was generated.

Info

console.info("Crocodiles eat 3-4 people per year"); 
Enter fullscreen mode Exit fullscreen mode

info

In firefox it displays with a small 'i' icon.

Testing

console.assert(1 === 2, "That is Wrong!"); 
Enter fullscreen mode Exit fullscreen mode

assert

Assert is fired only if something is false. So using assert we can test for something and if it is false it will throw an error.

clearing

console.clear(); 
Enter fullscreen mode Exit fullscreen mode

clear

It clears everything on the console.

Viewing DOM Elements

const p = document.querySelector("p"); console.log(p); 
Enter fullscreen mode Exit fullscreen mode

Using console.log(p) actual element is displayed.

p

console.dir(p); 
Enter fullscreen mode Exit fullscreen mode

But using console.dir(p) displays all the properties and methods associated with that element.

dir

Grouping together

const dogs = [   { name: "Snickers", age: 2 },   { name: "hugo", age: 8 }, ];  dogs.forEach((dog) => {   console.groupCollapsed(`${dog.name}`);   console.log(`This is ${dog.name}`);   console.log(`${dog.name} is ${dog.age} years old`);   console.log(`${dog.name} is ${dog.age * 7} dog years old`); }); 
Enter fullscreen mode Exit fullscreen mode

This is how the normal output is like:
without collapse

Now using grouping

dogs.forEach((dog) => {   //console.group(`${dog.name}`);   console.groupCollapsed(`${dog.name}`);   console.log(`This is ${dog.name}`);   console.log(`${dog.name} is ${dog.age} years old`);   console.log(`${dog.name} is ${dog.age * 7} dog years old`);   console.groupEnd(`${dog.name}`); }); 
Enter fullscreen mode Exit fullscreen mode

We can either use console.group() or console.groupCollapsed(), the collapsed displays output where the output groups are collapsed by default.

grouped

counting

console.count("Harsh"); console.count("Harsh"); console.count("Harsh"); console.count("Harsh"); console.count("Harsh"); 
Enter fullscreen mode Exit fullscreen mode

counts

It counts how many times we have used a specific word, or number, or object , or DOM node etc.

timing

console.time("fetching data"); fetch("https://api.github.com/users/cenacrharsh")   .then((data) => data.json())   .then((data) => {     console.timeEnd("fetching data");     console.log(data);   }); 
Enter fullscreen mode Exit fullscreen mode

!timing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3tz6gy97yiy1rmtcnq4.png)

If we want to track how long a particular task takes we can start a timer.

table

console.table(dogs); 
Enter fullscreen mode Exit fullscreen mode

It displays an array object in the form of a table.

table

and with this our project for the day was completed.

GitHub repo:

GitHub logo cenacrharsh / JS-30-DAY-9

Blog on Day-8 of javascript30

cenacr007_harsh

JavaScript-30-Day-8

KUMAR HARSH ・ Jun 8 '21

#javascript #html #webdev #github

Blog on Day-7 of javascript30

cenacr007_harsh

JavaScript-30-Day-7

KUMAR HARSH ・ Jun 7 '21

#javascript #html #github #webdev

Blog on Day-6 of javascript30

cenacr007_harsh

JavaScript-30-Day-6

KUMAR HARSH ・ Jun 6 '21

#javascript #css #html #webdev

Follow me on Twitter
Follow me on Linkedin

DEV Profile

You can also do the challenge at javascript30

Thanks @wesbos , WesBos to share this with us! 😊💖

Please comment and let me know your views

Thank You!

githubjavascriptproductivitywebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers
  • Author

    Refactoring for Efficiency: Tackling Performance Issues in Data-Heavy Pages

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.