Hii DEV family ð
In this article, we are discussing debug your code in javascript sound is good!. Let's start
Debugging your code is very important to solve a problem.
Ya yaa Error...! ðĪŊ
Lifelike an error. ð
Now how to solve it?
Console.log is helping to solve the error.
There are so many types to see the output in the console.
console.log
it's very simple and basic use in javascript programmer...!
ex:1
console.log("ðĪŠ");
ex:2
var name = 'Kuldeep';
console.log(name);
If you want to basic way to see an error you can go with it.
But what if we have multiple values that we want to log?
For example:
var name='kuldeep ðĪ';
var friendName='Pawar ð';
var car = ðïļ;
console.log(name);
console.log(firendName);
console.log(car);
That time we are console.log() 3-time write? No, I have an idea ðĄ.
I write code like this.
console.log('name'.name, 'My Friend Name'.firendName, 'car'.car);
But this is also long ð
I write code like this again...
console.log( {name, firstName, car} );
You can write this way your code line is less and you can easily understand to code what is. And You are a smart way programmer.
Let's work with Object:
let car ={
carName: 'BMW',
carColor: 'Black',
price: $250000,
}
console.log(car);
console.log({car});
The first log will print the properties within the car object. The second will identify the object as "car" and print the properties within it.
Variables within the log
console.log('%s is %d years old', "Kuldeep", 29 );
in this example, %s
is referred to as string options, and %d is referred to as any number. In this example our output statement is a show like this: Kuldeep is 29 years old
.
variants log().
There are a few variant logs. Mostly widely use console.log(). But there is also.
console.info('This is info message') ;
console.warn('Please enter valid number');
console.error('number is not valid');
console.debug('This is debug');
warn
print as yellow color and error
message print as red color
console.table()
console. table() is view beautiful table view with index number.
let animal = [
{
cow: "ðŪ",
cat: "ðą"
},
{
dog: "ðķ",
monkey:"ð"
}
]
Top comments (0)