Git Product home page Git Product logo

spaceship-javascript's Introduction

spaceship-javascript

Educational content for JavaScript

First steps

Clonse this repository to your local machine:

$ git clone https://github.com/paerallax/spaceship-javascript.git

Enter it:

$ cd spaceship-javascript

And install dependencies:

$ npm install

Open it with an editor of your choice. I specifically haven't included any linters yet as they'd solve the tests for you (:

Goal

In the src directory there are 2 files: primitives.js and primitives.spec.js. The first one is just a reminder of how types coerce and what typeof returns on each primitive (try to not look at this file at first :) ). The fun happens in primitives.spec.js. On the first 2 lines, we're importing a testing framework and an assertion library:

const mocha = require('mocha')
const assert = require('chai').assert

Then we see a bunch of describe blocks, starting from line 4. In simple terms you give it a string which is an expression or statement or just something in JavaScript that you want to describe. After that you pass to the it block (line 5) the description of above-mentioned expression/statement/etc., in plain English. Now, this all is already done for you, BUT the descriptions are misleading. Okay, they're not misleading, they're straight up incorrect (: Let's look at the one on line 6: (You need not worry about unfamiliar jargon or syntax of requiring a library, writing test blocks used here as it's not relevant to our exercies as of now. What's relevant is the code on lines 6, 12, 18 and so on: the assertions.

assert.strictEqual(typeof null, 'null')

It does the following:

typeof null === null

This is not correct. typeof null is something else (hint: historical reasons). All other describe blocks are not correct either. To test this, we can run:

$ npm run test

It should return a error log saying that all 7 tests fail. That is correct behavior, as all tests indeed contain a mistake. Your task it to change the arguments or method of comparison on assertions to make it correct.

Before going further, we should make the taxonomy clear:

strictEqual stands for (===)
equal stands for (==)

Considering this, let's solve one of these to get a grasp of how you can approach this. The last test says (on line 41): 0 as a number is strict equal to the boolean false because strict equal doesn't cast types

And then writes this same statement in a programmatic way on line 42:

assert.strictEqual(0, false)

Which does:

0 === false

In this case you should change strictEqual to equal because 0 isn't strict equal to false (0 === false isn't true), it's equal to false (0 == false). Hence change line 42 to:

assert.equal(0, false)

If we then run:

$ npm run test

We should get 6 errored and 1 passed test, the one test that we just corrected.

This is all there is to know. If you're confused about anything, get stuck or need explanation, please don't hesitate to ask one of the people around you and/or the speakers (:

spaceship-javascript's People

Contributors

metapragma avatar eduavet avatar

Watchers

James Cloos 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.