avatarKirti K

Summary

The web content provides a comprehensive guide for mastering JavaScript basics, focusing on the console object and its methods for interview preparation, as part of a 100-day JavaScript interview prep journey.

Abstract

The article titled "JavaScript Day 25 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation" is part of a series aimed at beginners preparing for JavaScript interviews. It delves into the console object, explaining its role in debugging and interacting with the browser's debugging console. The article covers various methods of the console object, such as console.assert(), console.clear(), and console.debug(), with examples and screenshots to illustrate their usage. The author emphasizes the importance of understanding these methods for effective debugging and application state inspection. The article concludes with a call to subscribe and support the author's blog, suggesting a commitment to sharing knowledge and fostering a respectful learning community.

Opinions

  • The author believes that a 100-day journey focused on learning and practice is rewarding for personal growth in JavaScript.
  • The console object is presented as a powerful tool for developers, particularly for logging messages, debugging, and inspecting application state.
  • console.assert() is highlighted as a method to enforce conditions and provide error messages when assertions fail, aiding in the development of robust applications.
  • console.clear() is seen as useful for maintaining a clean console environment, especially during debugging sessions.
  • The console.debug() method is recommended for logging debug messages and is considered beneficial for tracking and troubleshooting in production applications.
  • The author encourages the use of console methods with different log levels for more effective utility in common debugging scenarios.
  • The article promotes a culture of kindness and knowledge sharing within the developer community, emphasizing the value of respect and support for one another's work.

JavaScript Day 25 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation

100 Days of JavaScript Interview Prep: A Beginner’s Journey

JavaScript Day 25 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation

Welcome to Day 25–100 Days of JavaScript Interview Prep: A Beginner’s Journey

Embarking on a 100-day adventure focused on learning, practice, and growth sounds like an incredibly rewarding journey.

DAY 25 (April 16th, 2024) — Console.log or debugging method in JavaScript?

Answer —

Console — It is part of web-api and feature available in web-workers.

It’s exposed as Window.console, and can be referenced as console.

Console is an object in JavaScript which provides methods below advantages.

  1. It helps in interacting with the browser’s debugging console.
  2. It allow developers to log messages.
  3. It help in debugging code.
  4. It help to inspect the state of their applications.

How to Use It

Let’s start with simple example Usage

Simple Example

Console.log with string

console.log("Failed to open the specified link");

Open browser console window and paste the above line of code. You will see log will be printed in the window.

Output in browser console for Failed to open the specified link

Let’s now understand Console Methods and how we can use each of them.

1. console.assert()

The console.assert() static method writes an error message to the console if the assertion is false.

If the assertion is true, nothing happens.

function isEven(num) {
    console.assert(typeof num === 'number', "Error: Input must be a number");
    return num % 2 === 0;
}

console.log(isEven(4));  // Output: true
console.log(isEven('ghfjghfjgf'));  // will throw error

2. console.clear()

It is static method clears the console of any message.

Let’s understand with example —

First add some console.log with strings and add console.clear() method at the end.

You will notice all logs will be cleared from window or program

console.log("my first log");
console.log("my second log");

console.clear() // it will clear all above logs from window 

3. console.debug()

The console.debug() method is used to log debug messages to the console.

It is similar to console.log, but it is used for debugging purposes in application.

It is very useful for debugging the production ready application and tracking user journey for errors troubleshooting.

function login(username, password) {
    console.debug("user entered with encrypted function for login",username,password);
    return true;
}

console.log(login('gfdgf', 'mypwd')); 
The console.debug() method is used to log debug messages to the console.

In our real application, we usually used console.debug with log Level — We will learn in our comming session how to use console.log with different log Level in common utility.

Conclusion

This is the basic example to understand how console works and tomorrow we will continue with other method of console.

Happy Coding and Stay Tuned :)

Kind is cool !!!

Share knowledge to gain knowledge !!!!

Be kind and treat people with respect !!

If you find my blog helpful, then please subscribe, claps and follow to support :)

Thank you -JavaScript Day 25 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation
Interview
JavaScript
Frontend Interviews
Javascript Interview
Programming
Recommended from ReadMedium