Example 1:
Declare a variable called “name” and assign your name to it. Then, log the value of the variable to the console.
const name = "RAJI";
console.log("Name : ", name);
Output
Example 2:
Declare two variables called “num1” and “num2” and assign them any numerical values of your choice. Create another variable called “sum” and store the sum of num1 and num2 in it. Finally, log the value of “sum” to the console.
let num1 = 5;
let num2 = 10;
let sum = num1 + num2;
console.log(`sum of ${num1} and ${num2} is: ${sum}`);
Output:
Example 3:
Create a variable called “message” and assign it a string value. Then, create another variable called “messageLength” and store the length of the “message” string in it. Finally, log the value of “messageLength” to the console.
const message = "JS";
const messageLength = message.length;
console.log("Length of the message : " + messageLength);
Output:
Example 4:
Declare a variable called “isRaining” and assign it a boolean value representing whether it is currently raining or not. Then, log the value of “isRaining” to the console.
let isRaining = true;
console.log("currently is it raining", isRaining);
Output:
Views: 184