Practice Set 1 in JavaScript
//Question 1 :
//Create a variable of type String and try to add a number to it
let a = "Harry"
let b = 10
console.log(a + b)
//Question 2 :
//Use typeof operator to find the datatype of the string in last question
console.log(typeof (a + b))
//Question 3 :
//Create a const object in javascript can you change it to hold a number later ?
//Answer : No, we can not change it to hold a number later
const a2 = {
name: "Harry",
section: 1,
isPrinciple: false
}
// a2 = "Harry" //Will give Error
// a2 = 54 // Will give Error
//Question 4 :
//Try to add a new key to the const object in problem 3 were you able to do it ?
//Answer : Yes, we are able to do it as shown below
a2["friend"] = "Shubham"; //Add member in a2 Object
a2["name"] = "Prakash"; //Update member in a2 Object
console.log(a2)
// a2 = {} //We can't assign another Object to a2
//Question 5 :
//Write a JS program to create a word-meaning dictionary of 3 words
const dict = {
appreciate: "recognize the full worth of",
ataraxia: "a state of freedom from emotional disturbance and anxiety",
yakka: "work, especially hard work"
}
console.log(dict)
console.log(dict.appreciate)
console.log(dict["ataraxia"])
console.log(dict.yakka)
OUTPUT :
Harry10
string
{ name: 'Prakash', section: 1, isPrinciple: false, friend: 'Shubham' }
{
appreciate: 'recognize the full worth of',
ataraxia: 'a state of freedom from emotional disturbance and anxiety',
yakka: 'work, especially hard work'
}
recognize the full worth of
a state of freedom from emotional disturbance and anxiety
work, especially hard work
Comments
Post a Comment