Giter Site home page Giter Site logo

es6-exercises's Introduction

es6-exercises

Modify the following code to use var, const, and let appropriately. Replace the underlines with either 'var', 'const', or 'let'

const SPEED_OF_LIGHT = 299792458

var speedArray = [55, 9.8, 1000000000, 186300]

for (let i = 0; i < speedArray.length; i++) {
  if (speedArray[i] > SPEED_OF_LIGHT) {
    console.log("Faster than light")
  } else {
    console.log("Sub-light speed")
  }
}

What errors will the following code blocks produce? Why?

const foo = 5;
foo = 6;
var foo = 5;
if (foo > 3) {
  let bar = 2;
  foo = foo * bar;
}
console.log(foo);
console.log(bar);
const farge = {
  prop1: "one",
  prop2: "two",
  prop3: "three"
}
farge = {newProp: "new"};  // ANSWER: ERROR! - trying to assign new value to a constnat
farge.prop1 = "forty-two"; // ANSWER: No Error - can alter a object value even with const
farge.propX = "ex";        // ANSWER: No Error - will add new property to farge
delete farge.propX;        // ANSWER: No Error - allowed to alter object
console.log(farge);

Rewrite the following functions using arrow functions

var adder = function(a, b) {
  return a + b;
}

ANSWER: adder = (a, b) => a + b
function printFarge() {
  console.log('farge');
}

ANSWER: printFarge = () => console.log('farge')
var cleanTheString = function(str) {
  let newStr = str.replace(/\s/g, '');
  newStr = newStr.toUpperCase();
  return newStr;
}

ANSWER: cleanTheString = (str) => {
  let newStr = str.replace(/\s/g, '')
  newStr = newStr.toUpperCase();
  return newStr;
}

Use Object Literal shorthand to clean up the following code

var color = "blue";
var length = 14;
var style = "Flamenco";

var widget = {
  color,
  length,
  style
}

Use String Literals to make the following code more readable

var name = "Paco";
var location = "Nogales";
var food = "steak";

var bio = `${name} is from ${location} and really likes to eat ${food1}`;

The blocks below represent two separate files. Write out the statements needed to use the function from the first file in the code in the second file

// This is in hello.js
var hello = function(name) {
  console.log(`Hello, ${name}!`);
}
export default hello
// This is in main.js
import hello from './hello'

hello("Siouxsie");

es6-exercises's People

Contributors

kyleavb avatar sixhops avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.