Skip to content

Latest commit

 

History

History
174 lines (160 loc) · 2.34 KB

File metadata and controls

174 lines (160 loc) · 2.34 KB

2. JavaScript Variables


JavaScript is one of the most popular and dynamic programming languages out there.

Programs in the Videos

Strings

console.log("I love JavaScript");
console.log('JavaScript is fun');

Output

I love JavaScript
JavaScript is fun
console.log(`I love JavaScript`);
console.log(`JavaScript is fun`);

Output

I love JavaScript
JavaScript is fun

Numbers

console.log(8);
console.log(80.5);

Output

8
80.5

JavaScript Variables

let language = "JavaScript";
console.log(language);

Output

JavaScript

let number = 5;
console.log(number);

Output

5

var name = "Jack";
console.log(name);

Output

Jack

let name = "Punit"
console.log(name)
name = "James"
console.log(name)

Output

Punit
James

Variable Using const

const passportNumber = 39983;
console.log(passportNumber);

Output

39983

Changing Value in const

const passportNumber = 39983;
console.log(passportNumber);

passportNumber = 44325;
console.log(passportNumber);

Output

TypeError: Assignment to constant variable.

JavaScript undefined

let name;
console.log(name);

Output

undefined

let name = "Punit";
console.log(name);

name = undefined;
console.log(name);

Output

Punit
undefined

Print variables and string in single line

let city = "New York";
console.log("City: " + city);

Output

City: New York

Template Literal

let city = "New York";
console.log(`City: ${city}`);

Output

City: New York

let city = "New York";
let kfcLocation = 10;
console.log("City: " + city +  ", " + "KFC Locations :" + kfcLocation);

Output

City: New York, KFC Locations :10

Another Example

let city = "New York";
let kfcLocation = 10;

console.log(`City: ${city}, KFC Locations: ${kfcLocation}`);

Output

City: New York, KFC Locations :10

Programmiz Quiz

Q. Which of the following is the correct variable name?

  1. switchNumber
  2. 1switchNumber
  3. switch number
  4. switch

Answer: 1