forked from faisal2410/js_basic_ostad_b3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_variables.js
67 lines (50 loc) · 1.92 KB
/
1_variables.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// In JavaScript, variables are used to store data values.They can be declared using the "var", "let", or "const" keywords, and the type of value they can store can be changed during the program execution.
// Here's an example of how to declare and use a variable in JavaScript:
// Declare a variable named "fname" and assign it the value "John"
var fname = "John";
// Print the value of the "name" variable to the console
console.log(fname);
// Change the value of the "fname" variable to "Jane"
fname = "Jane";
// Print the updated value of the "fname" variable to the console
console.log(fname);
// In this example, we first declare a variable named "name" and assign it the value "John".We then print the value of the "name" variable to the console using the "console.log()" method.
// Next, we change the value of the "name" variable to "Jane" and print the updated value to the console again.Since we used the "var" keyword to declare the variable, it can be reassigned to a different value later in the program.
// Variables are a fundamental concept in JavaScript and are used to store all kinds of data, from simple strings and numbers to more complex objects and arrays.
/*
Ref :
https://www.w3schools.com/js/js_variables.asp
*/
// 1. What is the value of x after the following code is executed?
var x;
console.log(x); // Output: undefined
// A. undefined
// B. null
// C. 0
// D. ""
// Answer: A. undefined
// 2. What is the value of y after the following code is executed?
var y = 5;
console.log(y); // Output: 5
// A. undefined
// B. null
// C. 0
// D. 5
// Answer: D. 5
// 3. What is the value of z after the following code is executed?
var z = "Hello";
console.log(z); // Output: "Hello"
// A. undefined
// B. null
// C. 0
// D. "Hello"
// Answer: D. "Hello"
// 4. What is the value of w after the following code is executed?
var w = 10;
w = w + 5;
console.log(w); // Output: 15
// A. 5
// B. 10
// C. 15
// D. 20
// Answer: C. 15