Commit ea9bb4f7 authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

Variable mutation and type coercion

parent 774a58ae
/***************************** /*****************************
* Variables and data types * Variables and data types
*/ */
/*
var firstName = 'John'; var firstName = 'John';
console.log(firstName); console.log(firstName);
var lastName = 'Smith'; var lastName = 'Smith';
...@@ -15,5 +15,25 @@ console.log(job); ...@@ -15,5 +15,25 @@ console.log(job);
// Variable naming rules // Variable naming rules
var _3years = 3; var _3years = 3;
var johnMark = 'John and MArk'; var johnMark = 'John and MArk';
*/
/*****************************
* Variable mutation and type coercion
*/
var firstName = 'John';
var age = 28;
// Type coercion
console.log(firstName + ' ' + age);
var job, isMarried;
job = 'teacher';
isMarried = false;
console.log(firstName + ' is a ' + age + ' year old ' + job + '. Is he married? ' + isMarried);
// Variable mutation
age = 'twenty eight';
job = 'driver';
alert(firstName + ' is a ' + age + ' year old ' + job + '. Is he married? ' + isMarried);
var lastName = prompt('What is his last Name?');
console.log(firstName + ' ' + lastName);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment