Skip to content

Instantly share code, notes, and snippets.

@ianmstew
Last active November 30, 2018 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianmstew/36713feaeebb85f1b601c34bc83b3a45 to your computer and use it in GitHub Desktop.
Save ianmstew/36713feaeebb85f1b601c34bc83b3a45 to your computer and use it in GitHub Desktop.

Links

Boolean values and operators

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Logical

let isRaining = true;
let isDaytime = true;
let shouldIGoForAWalk = !isRaining && isDaytime;

console.log('Should I go for a walk?', shouldIGoForAWalk);

String values and operators

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#String

let firstName = 'Zoe';
let lastName = 'Proom';
let fullName = firstName + ' ' + lastName;

console.log('Full name:', fullName);

Numerical values and operators

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Arithmetic_operators

let a = 1.5;
let b = 2;
let product = a * b;

console.log('Product:', product);

undefined and null

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null

// undefined
let someVariable;

console.log('someVariable:', someVariable);

someVariable = null;

console.log('someVariable:', someVariable);

Conditionals with booleans

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals

let isRaining = true;
let isDaytime = true;
let shouldIGoForAWalk = !isRaining && isDaytime;

console.log('shouldIGoForWalk:', shouldIGoForAWalk);

if (shouldIGoForAWalk) {
  console.log("Let's go!");
} else {
  console.log("I'd better not.");
}

Conditionals with strings

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals

// INPUTS

let fullName = 'Zoe Proom';
let userRole = 'read'; // read, write, admin

// APPLICATION

console.log(fullName +' is attempting to administer...');

// === here is converting the _contents_ of `userRole` and the string literal 'admin' to a boolean
if (userRole === 'admin') {
  console.log('Success!')
} else {
  console.log('Access denied.')
}

Truth and falsy

Falsy: https://developer.mozilla.org/en-US/docs/Glossary/Falsy

if ('' || 0 || null || undefined || false) {
  console.log('falsy');
} else {
  console.log('truthy');
}

ASSIGNMENT: Conditionals with numbers

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals

// INPUTS

let userName = 'Jane';
let userAge = 17;

// APPLICATION

// TODO: Print (with console.log) "Jane is a minor" if userAge is less than 18, otherwise print "Jane is an adult"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment