DEV Community

loading...

Week 7 of JS Bootcamp!

codetivated profile image Melissa Heying ・Updated on ・2 min read

Week 7 started out rough. The first few days I felt lost again; Like a deer in headlights lost. Nothing was really clicking and that started to worry me. Things that I thought I knew started to confuse me and I couldn't even understand some of my code.

Alt Text

That's when I decided to go back and watch some Youtube videos of the basics of Javascript. Even though I've been taught the basics, I wasn't fully understanding it. I knew that Boolean means true or false but I didn't know why you would want to use a Boolean. And then it was like the Javascript Gods heard me because we built an app that used a Boolean to start and stop a timer. So that timing was super cool πŸ”₯.

Alt Text

I'm still working on asking questions, but I had a breakthrough Thursday when I stayed after and asked to go over every little bit of code in one of our apps πŸ”. I asked the "dumbest" questions but I'm so happy that I did because my instructor was able to provide answers to those questions. That ended up putting me back on track to where I was able to get really far on one of my assignments the next day.

Alt Text

All morning my logic was on point πŸ₯…. When I would get stuck on something, I got up and walked around, which generated ideas and solutions. It was great. Now that I'm starting to think logically, the next thing I need to work on is getting the syntax down. It's really cool to know what I need to work on, haha!

Alt Text

I'm super excited for this following week. We got a little sneak peek on Friday of what backend Javascript is going to look/be like. We got to see a sample of Hello World in a HTTP web server (example below) and I found out that NodeJS has it's own console which is completely different than a Browser console.


const http = require('http')

const port = process.env.PORT

const server = http.createServer((req, res) => {
  res.statusCode = 200
  res.setHeader('Content-Type', 'text/html')
  res.end('<h1>Hello, World!</h1>')
})

server.listen(port, () => {
  console.log(`Server running at port ${port}`)
})

Enter fullscreen mode Exit fullscreen mode

I'll let you guys know more about Server Side Javascript next week!! πŸ’š

Discussion (2)

pic
Editor guide
Collapse
functional_js profile image
Functional Javascript • Edited

Hey Melissa,
Way to keep rewiring those neurons! :)

It'll all sink in over time.
There's an old express... "Nothing is so full of victory as patience."

As for the boolean type (a type that can only represent one of two values (mutually exclusive); true or false)


I never use "true" or "false" explicitly in JS (javascript)

//not good
if (x === true) {
// do something
}


I also never do this, but you will see this idiom commonly used by many...

//not good
if (x) {
// do something
}

//not good
if (!x) {
// do something
}


To handle truthy and falsy values, I use predicate functions (functions whose return type is a boolean)
There's a naming conventions for these type of funcs, which is to prefix them with "is" and sometimes "has")

//good
if (isArray(arr1)) {
// do something
}


A more complex boolean set (using either && and ||) should be evaluated before the "if header" to be more readable.
(here is a somewhat contrived example for demo purposes)...

//good

const isValidData = isArray(arr1) && isNotEmptyArr(arr1) && isArrOfNumbers(arr1);

if (isValidData) {
// do something
}
Collapse
codetivated profile image
Melissa Heying Author

Thanks so much for your time in typing all that out! We’re starting to use booleans like your last example!