GithubHelp home page GithubHelp logo

gerhynes / dev-tools Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 2 KB

Exercises to practice Chrome developer tools. Part of Wes Bos' JavaScript 30 course.

JavaScript 87.17% HTML 12.83%
chrome-devtools javascript javascript30

dev-tools's Introduction

Chrome Dev Tools Tricks

Exercises to practise using the Chrome developer tools. Part of Wes Bos' JavaScript 30 course.

Screenshot of Chrome Dev Tools in use

Quick debugging

To see what JavaScript is modifying an element, inspect the element, find it in the DOM, right click, click on 'break on...' and 'attribute modifications'.

Now when you click on the element and trigger the JavaScript, a debugger command is run. It pauses exactly when the element is modified and shows the line of code that is causing the element's attribute to be modified.

Console methods and more

These also work in Firefox's console.

Regular

console.log outputs to the console.

Interpolated

You can interpolate arguments into console.log

console.log("Hello, I am a %s string", "test");

To some extent this has been replaced by ES6 backticks.

console.log(Hello, I am a ${var} string);

Styled

You can style text in the console with %c:

console.log('%c I am some great text', 'font-size: 50px; background: red;');

Table

console.table() displays data (e.g. an array of objects) as a table.

Warning

console.warn() outputs a warning message.

console.warn("OH NOOOOO!!");

Error

console.error() outputs an error message to the console.

console.error("Feck!");

Info

console.info() outputs an informational message to the console (marked with an "i" icon).

console.info("Crocodiles eat 3-4 people per year");

Testing

console.assert() checks if things are true. It writes an error message to the console if the assertion is false.

console.assert(1 === 2, "That is wrong");
const p = document.querySelector("p");
console.assert(p.classList.contains("ouch"), "That is wrong");

Clear

console.clear() will clear your console.

Viewing DOM elements

console.dir() gives you an interactive list of the properties and methods of the element you pass to it.

Grouping things together

console.group() creates a new inline group, indenting all following output by another level.

console.groupCollapsed() also creates an inline group but starts with the group collapsed.

console.groupEnd() moves back out a level.

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`);
  console.groupEnd(`${dog.name}`);
});

Counting

console.count() logs the number of times you call that line with a specific label.

Timing

console.time() starts a timer.

console.timeEnd() stops the specified timer.

console.time("Fetching data");
fetch("https://api.github.com/users/wesbos")
  .then(data => data.json())
  .then(data => {
    console.timeEnd("Fetching data");
  });

dev-tools's People

Contributors

gerhynes avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.