JavaScript console.log() All Details With Example.
JavaScript console.log() All Details With Example.
6 November, 2022
By Apu
Here the console is an object and the log() is a method. To access the log() method, the console object is used with a dot-operator.
Syntax
console.log(a);
Example : console.log() hello world.
<script>
console.log("Hello World")
</script>
// output => Hello World
Passing a variable as a parameter
<script>
const a = "Hello World";
console.log(a);
</script>
// output => Hello World
Passing a number as a parameter.
<script>
const a = 5;
console.log(a);
</script>
// output => 5
Pass an object to the console.log() method
<script>
const color = {
name : "red",
code: "#ff0000"
}
console.log(color)
</script>
Example : passing an array as a parameter.
<script>
const color = {
name : "red",
code: "#ff0000"
}
console.log(color)
</script>