JavaScript Fundamentals: Learning the Language of the Web
JavaScript console.log() Method
JavaScript's console.log() function is used to print any variables that have been defined in the program or to display any other message to the user.
Syntax:
Parameters: It accepts a parameter, which may be an object, an array, or any message.
Return value: This function returns the value of the given parameter.
Here are some examples of JavaScript code that show how this function works:
A number as an argument: The console.log() function will display the number if a number is given as an argument.
Example 1:
Output:
String as an argument: If a string is supplied as an argument to the console.log() function, the function will show the string.
Example 2:
Output:
A char as an argument: If a char is given as an argument to the console.log(), then it will be displayed by the function.
Example 3:
Output:
A message as an argument: The function will display the message if the console.log() function is passed with the message.
Example 4:
Output:
A function as an argument: If a function is provided as an argument to the function console.log(), it will display the value of the given function.
Example 5:
Output:
A number with a message as an argument: When a number is supplied to the console.log() function, then it will display the number along with the given message.
Example 6:
Output:
A message with string as an argument: If the string is submitted to the console.log() function, it will be displayed alongside the given message.
Example 7:
Output:
A message with char as an argument: If the char is submitted to the console.log() function, it will be displayed alongside the given message.
Example 8:
Output:
The console.log() function is supported by the below browsers:
- Edge 12 or above
- Chrome 1 or above
- Firefox 4 or above
- Safari 3 or above
- Opera 10.5 or above
- Internet Explorer 8 or above
Javascript is mostly used in creating web pages, but it is a versatile language and can be used for a wide range of applications, such as developing web apps and mobile apps for Android and iOS.