Javascript Values part 1

Primitive Data Types

Immutables (not chageables)

// Primitive Data Types 
String // 'Javascript is awesome!', "Really awesome!"
Number // 4, 150, 2345, 4.5
Boolean // true, false, -1, 0, 1, 
null // "defined" as no value
undefined // not yet defined

Strings

The data type for plain language

Strings

// Javascript Strings

// RULE 1: Must be between balanced quotes
typeof 'Javascript is awesome!'; // 'string'

// RULE 2: Escape special characters
'Can\'t beat Javascript so don\'t try';
// RULE 3: Can have numbers, symbols, ANYTHING
'Jenny\'s #: ($%@)867-5309';

Strings

// Javascript Strings

// Indexed, starting at 0
'Dancing in the street'[0]; // "D"
 0123456789...
// Immutable 
'I hear, the secrets that...'
 0123456789...
// Iterable (can loop through)
for (var index = 0; index < 9; index++) {
  console.log('JScript'[index]);
} 

// "J", "S", "c", "r", "i", "p", "t"

[2] = 'f';

// NOPE!!! 

Strings

  • Primitive Javascript Data Type
  • Immutable (no editing)
  • Characters, symbols, numbers
  • Escape special characters
  • Must be between balanced quotes
Key Takeaways

Strings Exercises!!!

  • Find a pair - ("Driver" and "Navigator")
  • Set up your work environments
  • Slides: Pair Programming
  • NAVIGATOR - TELLS DRIVER WHAT TO TYPE
  • DRIVER - HANDS ON KEYBOARD
  • Switch roles every 10 mins or 3 problems
  • Spend 1-2 minutes reviewing code
  • Share code with codeshare.io/[Share this!]
Instructions:
"Coding tiiiime"

HELP???

Let's code!!!
  1. Lecture Slides
  2. Google
  3. w3schools
  4. stackoverflow
  5. mdn.io
  6. TA/Teacher

Numbers

Just do all the stuff you do with numbers...

Numbers

// Javascript Numbers

// Numbers are numbers
13, 2357, 5634634564356456

// Decimals too
45.33466362363

JavaScript Memory

563463456...

2357

45.3346636...

13

Numbers

// Javascript Numbers

// Mathmatical operations
> 21 + 7: // ???
> 3.14 + 5: // ???
> 3 * 5; // ???
> 15 / 3 // ???
> 15 % 9; // ???

JavaScript Memory

3 * 5

3.14 + 5

15 / 3

21 + 7

15 % 9

Numbers

// Javascript Numbers

// Mathmatical operations
> 21 + 7: // ???
> 3.14 + 5: // ???
> 3 * 5; // ???
> 15 / 3 // ???
> 15 % 9; // ???

JavaScript Memory

15

8.4

5

28

6

Numbers Methods(helpers)

// Javascript Numbers' "METHODS"

// Is this a number?
typeof 523454      // ???

// 'STRINGIFY' this number
55.00.toString();  // ???
77.toString();     // ???
(99).toString();   // ???

// Numberify a 'STRINGIFIED'
Number('453');     // ???

JavaScript Memory

ERROR

55

"99"

"number"

453

Numbers Methods(helpers)

// Javascript Numbers Methods

// When adding numbers
600 + '400'; // ???

// When using some methods
54.435345.toFixed(2); // ???

// Combining methods and operations
10 + 54.435.toFixed(2); // ???

// Just to be safe???
Number(10 + 54.435.toFixed(2)); // ???

JavaScript Memory

"1054.44"

"54.44"

Try it!

"600400"

Be Careful and pay attention to detail!

JavaScript Memory

64.44

54.441

1054.44

Numbers Methods (helpers)

// Javascript Numbers Methods

// What's this???
Number(10 + 54.435.toFixed(2)); 

Be Careful and pay attention to detail!

// And what about this?
Number(54.435.toFixed(2) + 10); 
// And this?
Number(54.435345.toFixed(2)) + 10; 
// Javascript Numbers Methods

Numbers

  • Primitive Javascript Data Type
  • Immutable (no editing)
  • Do number stuff
  • Be careful when using methods
  • Be when using with strings
Key Takeaways

Numbers

Let's code!!!

[Add link to exercises here and/if directions]

[Anything else?]:

new pairs?

how long?

Resources?

Booleans

True, False | Truthy <> Falsy

Booleans

True, False | Truthy <> Falsy

"Bool"

// True

// Absolute truth
> 4 === 4; // true

> 4 !== 5; // True

> typeof 'BBoys make some noise...' === "string"; // true

// Relative truth
> if ('Moose rocks dance floors') console.log(true);


// Write a function that returns true if Moose rocks dance floors
> (function() { })()
 var indeed = false;

 if ('Moose rocks dance floors') indeed = true;

 console.log(indeed);

// Create function that explains the 5 goat rappers
> (function() {
    var isTheGoat = false;
    
    // Google it!
    var goat = prompt("Who are the 5 goat rappers?").toUpperCase();
    
    // Check if the 'goat' is the correct answer
    if (goat === 'DYLAN') {      
      // Is the goat?
      isTheGoat = true;

      // if correct, tell us who
      for (var i = 0; i < 5; i++) {alert(goat + '!')};
      
      // Then tell us why
      setTimeout(function() {alert('BECAUSE I SPIT HOT FIRE!')}, 2000);
      
      // Break out of the function and tell us the truth 
      return isTheGoat; // OPTIONAL
    
    }

    return isTheGoat;
  })();


// Absolute equivalence

// Is 4 equal to 4
> 4 === 4; // true

// Is 4 not equal to 5
> 4 !== 5; // true

// Is 4 greater than 5
> 4 > 5; // false

// Is this the correct data type
> typeof 'BBoys make some noise...' === "string"; // true

> typeof 'Love is a battlefield!' === "number"; // false
// Absolute Equivilence

JavaScript Memory

false

true

true

// Is 4 equal to 4
> 4 === 4; // ???
// Is 4 not equal to 5
> 4 !== 5; // ???
// Is 4 greater than 5
> 4 > 5; // ???

"Bool"

// True

// Absolute truth
> 4 === 4; // true

> 4 !== 5; // True

> typeof 'BBoys make some noise...' === "string"; // true

// Relative truth
> if ('Moose rocks dance floors') console.log(true);


// Write a function that returns true if Moose rocks dance floors
> (function() { })()
 var indeed = false;

 if ('Moose rocks dance floors') indeed = true;

 console.log(indeed);

// Create function that explains the 5 goat rappers
> (function() {
    var isTheGoat = false;
    
    // Google it!
    var goat = prompt("Who are the 5 goat rappers?").toUpperCase();
    
    // Check if the 'goat' is the correct answer
    if (goat === 'DYLAN') {      
      // Is the goat?
      isTheGoat = true;

      // if correct, tell us who
      for (var i = 0; i < 5; i++) {alert(goat + '!')};
      
      // Then tell us why
      setTimeout(function() {alert('BECAUSE I SPIT HOT FIRE!')}, 2000);
      
      // Break out of the function and tell us the truth 
      return isTheGoat; // OPTIONAL
    
    }

    return isTheGoat;
  })();


// Absolute equivalence

// Is 4 equal to 4
> 4 === 4; // true

// Is 4 not equal to 5
> 4 !== 5; // true

// Is 4 greater than 5
> 4 > 5; // false

// Is this the correct data type
> typeof 'BBoys make some noise...' === "string"; // true

> typeof 'Love is a battlefield!' === "number"; // false
// Absolute Equivilence

JavaScript Memory

false

false

true

// Is this the correct data type
> typeof 'B, BBoys and [B]Girls' === "string";
// Is this the correct data type
> typeof 'Love is a battlefield!' === "function";
// Is this the correct data type
> typeof function letsDance() {} === "number";

"Bool"

// True

// Absolute truth
> 4 === 4; // true

> 4 !== 5; // True

> typeof 'BBoys make some noise...' === "string"; // true

// Relative truth
> if ('Moose rocks dance floors') console.log(true);


// Write a function that returns true if Moose rocks dance floors
> (function() { })()
 var indeed = false;

 if ('Moose rocks dance floors') indeed = true;

 console.log(indeed);

// Create function that explains the 5 goat rappers
> (function() {
    var isTheGoat = false;
    
    // Google it!
    var goat = prompt("Who are the 5 goat rappers?").toUpperCase();
    
    // Check if the 'goat' is the correct answer
    if (goat === 'DYLAN') {      
      // Is the goat?
      isTheGoat = true;

      // if correct, tell us who
      for (var i = 0; i < 5; i++) {alert(goat + '!')};
      
      // Then tell us why
      setTimeout(function() {alert('BECAUSE I SPIT HOT FIRE!')}, 2000);
      
      // Break out of the function and tell us the truth 
      return isTheGoat; // OPTIONAL
    
    }

    return isTheGoat;
  })();


// Relative Equivilence

JavaScript Memory

false

false

true

// Does Moose rock dance floors
> if ('Moose rocks dance floors') {
    console.log(true);
  } // ???
// Is this the correct data type
> typeof 'Love is a battlefield!' === "function";
// Is this the correct data type
> typeof function letsDance() {} === "number";

Edit values part 1

By telegraphprep

Edit values part 1

  • 707