-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvm_tc.js
29 lines (21 loc) · 997 Bytes
/
vm_tc.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
/**
* Variable Mutation & Type Coercion
*/
/* Type Coercion */
var firstName = 'Chandrabhatta';
var age = 24;
// String Type data when coerced to Number, the String Type wins:
console.log(firstName + " " + age);
var job, isMarried, isAmazing; // job, isMarried & isAmazing are undefined.
job = 'Software Engineer';
isMarried = false;
// String Type data when coerced to Boolean/undefined, the String wins, i.e., everything is converted to String data
console.log(firstName + ' is a ' + age + ' year old ' + job + '. Is he Married? ' + isMarried + '. Is he Amazing? ' + isAmazing);
/* Variable Mutation */
age = "twenty four";
job = "unemployed";
// We can use the alert() function to alert the browser
alert(firstName + ' is ' + age + ' years old & is ' + job + '. Is he Married? ' + isMarried + '. Is he Amazing? ' + isAmazing);
// We can ask for user input using prompt() function
var lastName = prompt("What's " + firstName + "'s Last Name?");
console.log(firstName + " " + lastName);