These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Mar 2018
Tess0704
@Tess0704
Mar 01 2018 03:47
https://codepen.io/haishi0704/pen/ddQJMx only when click twice ,would the content change, also ,when the dom is first time rendered, nothing appers,only when click one of the two red buttons will the content appear. can't figure out why
Claudio Restifo
@Marmiz
Mar 01 2018 04:09
@Tess0704 react re-renders automatically only when states or props changes.
In your method you are updating this.users but not changing any state with it, so no re-rendering
abraham anak agung
@padunk
Mar 01 2018 04:19
@Tess0704 also if you want to write class in React it will be className and you need key properties when render each child in an array.
CamperBot
@camperbot
Mar 01 2018 04:39
tess0704 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1178 | @marmiz |http://www.freecodecamp.org/marmiz
Tess0704
@Tess0704
Mar 01 2018 04:39
it's working now
@padunk thanks I'll check it
CamperBot
@camperbot
Mar 01 2018 04:44
tess0704 sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 460 | @padunk |http://www.freecodecamp.org/padunk
啊吖嗄
@LinHuijuan
Mar 01 2018 05:02
var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[0]; // 等于 [1,2,3]
arr[1][2]; // 等于 6
arr[3][0][1]; // 等于 11
and 11?excuse me?
no problem now, sorry
Tess0704
@Tess0704
Mar 01 2018 05:58
need help again lol https://codepen.io/haishi0704/pen/mXvqyp extremely weird just wanna to show a ''hello world", nothing comes out
Brad
@bradtaniguchi
Mar 01 2018 06:01
@Tess0704 Look at your browser console, it looks like your getting errors as ReactDOM not being defined
it also says react wasn't loaded before it so theres multiple errors
Tess0704
@Tess0704
Mar 01 2018 06:14
@bradtaniguchi understand & solved I need to load React before ReactDOM
Ming Zhang
@mingsky1987
Mar 01 2018 06:33
I have question about Profile Lookup
function lookUp(firstName, prop){
// 请把你的代码写在这条注释以下
for (var i=0;i<contacts.length;i++) {
if (firstName!==contacts[i].firstName) {
console.log("No such contact");
}
else if (contacts.hasOwnProperty(prop)===0) {
console.log("No such property");
}
}
return contacts[i][prop];
who can help me?
anybody online?
Brad
@bradtaniguchi
Mar 01 2018 06:35
@mingsky1987 what is your question? I also can't read chinese so I can't read that comment
also use backtics to format the code so we can read it better
Ming Zhang
@mingsky1987
Mar 01 2018 06:36
function lookUp(firstName, prop){
for (var i=0;i<contacts.length;i++) {
if (firstName!==contacts[i].firstName) {
console.log("No such contact");
}
else if (contacts.hasOwnProperty(prop)===0) {
console.log("No such property");
}
}
return contacts[i][prop];
Brad
@bradtaniguchi
Mar 01 2018 06:37
What is your issue?
Fabien SHAN
@X140hu4
Mar 01 2018 06:38
Ming Zhang
@mingsky1987
Mar 01 2018 06:38
i can't pass Profile Lookup
Markus Kiili
@Masd925
Mar 01 2018 06:41
@mingsky1987 The first if should check whether it is the contact you look for.
Second should be just if(contacts[i].hasOwnProperty(prop)){...}
You should use two nested if's. No elses needed.
Ming Zhang
@mingsky1987
Mar 01 2018 06:49
cannot read property 'likes' of undefined
always type error
abraham anak agung
@padunk
Mar 01 2018 06:50
@mingsky1987 show your code again
Ming Zhang
@mingsky1987
Mar 01 2018 06:51

function lookUp(firstName, prop){
for (var i=0;i<contacts.length;i++) {
if (firstName!==contacts[i].firstName) {
console.log("No such contact");
if (contacts[i].hasOwnProperty(prop)===0) {
console.log("No such property");
}
}

}
return contacts[i][prop];

abraham anak agung
@padunk
Mar 01 2018 06:51
function lookUp(firstName, prop){
for (var i=0;i<contacts.length;i++) {
    if (firstName!==contacts[i].firstName) {
      console.log("No such contact");
      if (contacts[i].hasOwnProperty(prop)===0) {
    console.log("No such property");
    }
  }

 }   
  return contacts[i][prop];
Ming Zhang
@mingsky1987
Mar 01 2018 06:52
image.png
abraham anak agung
@padunk
Mar 01 2018 06:53
@mingsky1987 like @Masd925 said, you must check for the contact first, that's mean using ===. If the contact exist, check the property, if the property exist, return it.
Markus Kiili
@Masd925
Mar 01 2018 07:04
@mingsky1987 That code will shout No such contact, if the first looped contact is not the one you look for. So make positive tests inside the loop.
Ming Zhang
@mingsky1987
Mar 01 2018 07:06
i change my code like this
image.png
but not pass
abraham anak agung
@padunk
Mar 01 2018 07:07
@mingsky1987 close, you need to wait for the loop to finish to return no contact. And you can copy paste your code using ```
Ming Zhang
@mingsky1987
Mar 01 2018 07:09
thanks,it works.
Ming Zhang
@mingsky1987
Mar 01 2018 07:14
function lookUp(firstName, prop){
for (var i=0;i<contacts.length;i++) {
if (firstName===contacts[i].firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
return "No such property";
}
}
return "No such contact";
thanks again
Fabien SHAN
@X140hu4
Mar 01 2018 07:15
@mingsky1987 Please use three backticks before and after your code ```. (edit your message and add it to the line before and after)
Markus Kiili
@Masd925
Mar 01 2018 07:17
@mingsky1987 :+1:
Christopher McCormack
@cmccormack
Mar 01 2018 15:05
If anyone is interested, JSConf Iceland started early this morning - looks like plenty of fun talks! https://2018.jsconf.is/ Hopefully they'll be up individually on https://www.youtube.com/channel/UCzoVCacndDCfGDf41P-z0iA pretty soon.
Jason Luboff
@JLuboff
Mar 01 2018 16:15
@cmccormack morning
Ken Haduch
@khaduch
Mar 01 2018 16:17
@JLuboff - good morning to you, and @cmccormack and anyone else dropping in...
Jason Luboff
@JLuboff
Mar 01 2018 16:18
@khaduch Morning! How's it going?
Ken Haduch
@khaduch
Mar 01 2018 16:26
@JLuboff - going okay... I was just trying to help someone with a C program in the help room... but I think that they went away. :) It's funny how people come here and ask random programming questions.
how are things with you?
Christopher McCormack
@cmccormack
Mar 01 2018 16:27
@JLuboff @khaduch heya!
Jason Luboff
@JLuboff
Mar 01 2018 16:40
@khaduch Not bad. Working on a project for work and showed it off yesterday (current progress... probably 25% done) and overall the individuals were happy with it.
@cmccormack Whats the good word?
Christopher McCormack
@cmccormack
Mar 01 2018 16:40
@JLuboff nm, working and brushing up on some advanced python features
Ken Haduch
@khaduch
Mar 01 2018 16:41
@cmccormack - I just checked out your home page - nice looking page! I like the color scheme.
Christopher McCormack
@cmccormack
Mar 01 2018 16:41
@khaduch thanks! It's probably the last project I put any design effort into that involved color :joy:
CamperBot
@camperbot
Mar 01 2018 16:41
cmccormack sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3764 | @khaduch |http://www.freecodecamp.org/khaduch
Ken Haduch
@khaduch
Mar 01 2018 16:42
@cmccormack @cmccormack - it looks great - did you use one of those color selection websites or come up with it on your own?
Jason Luboff
@JLuboff
Mar 01 2018 16:42
@cmccormack Fun stuff! (I think, never worked with python)
Christopher McCormack
@cmccormack
Mar 01 2018 16:43
@khaduch I believe I used Adobe Kuler https://color.adobe.com/explore/?filter=most-used&time=month
@JLuboff python is alright, the more I work with JS though the less I want to work with Python. I think it's because they do comparable things but JS is built for the browser and that's where it seems everything is headed
Jason Luboff
@JLuboff
Mar 01 2018 16:45
I agree (that everything seems to be headed to the browser). C# while it can be built into the browser via ASP.net, it seems more attune to application style building but I'm also a mere beginner with it haha
Christopher McCormack
@cmccormack
Mar 01 2018 16:45
But if you're just parsing files or something python can be much quicker to setup and work with
jusgoose
@gusd773
Mar 01 2018 16:46
anybody know how / where I can get a background image that won't pixelate when I make it cover my entire page?
Christopher McCormack
@cmccormack
Mar 01 2018 16:46
@gusd773 get a bigger background image
Jason Luboff
@JLuboff
Mar 01 2018 16:47
@gusd773 https://blog.snappa.com/free-stock-photos/ Here's a list of 21 different websites with free stock images, generally they are of decent resolution
I've used stocksnap.io for several i nthe past
Nate Mallison
@NJM8
Mar 01 2018 16:49
hey all,

Can anyone help me with my random quote generator? https://njm8.github.io/FreeCodeCampFrontEndProjects/randomQuoteGenerator/
I'm using this css to load the image full viewport with no overflow:

html { 
  background: url(01860_sanfrancisco_2560x1600.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

but it is disabling my button
for some reason the waves class does nothing and clicking the button does nothing
If I remove the css for the image it works fine. I have also tried a couple different methods to do the back ground image from this article: https://css-tricks.com/perfect-full-page-background-image/. And they all have the same affect on the button.

Christopher McCormack
@cmccormack
Mar 01 2018 16:49
You can also just use google image search and look for specific resolutions and enable the Labeled for Reuse licensing
jusgoose
@gusd773
Mar 01 2018 16:50
@cmccormack idk if you're trolling me sometimes or not so I'm gonna assume you meant that but I was hoping for a less trivial solution
@JLuboff thank you
CamperBot
@camperbot
Mar 01 2018 16:50
gusd773 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2347 | @jluboff |http://www.freecodecamp.org/jluboff
Christopher McCormack
@cmccormack
Mar 01 2018 16:51
@gusd773 not trolling - if the image is too small it will pixelate
Jason Luboff
@JLuboff
Mar 01 2018 16:51
Sometimes a part of learning is googling things
jusgoose
@gusd773
Mar 01 2018 16:52
@cmccormack I get that but I promise you I will consult lord Google before coming here I usually google for hours before I give up and ask for help
/ youtube
Christopher McCormack
@cmccormack
Mar 01 2018 16:52
haha I didn't suggest he google the answer but google for images that are larger
Did anyone actually read what I said?
Jason Luboff
@JLuboff
Mar 01 2018 16:54
I don't like to read, I just gloss over things and pick out the most offensive parts
Christopher McCormack
@cmccormack
Mar 01 2018 16:55
I figured :D
Jason Luboff
@JLuboff
Mar 01 2018 16:57
Ain't nobody got time for that!
jusgoose
@gusd773
Mar 01 2018 17:09
@JLuboff @cmccormack any suggested dimensions to search for?
Christopher McCormack
@cmccormack
Mar 01 2018 17:09
1920x1080 at a min probably - 2k or 4k
Jason Luboff
@JLuboff
Mar 01 2018 17:10
I agree, in general, most computers are running at minimum 720i (1360 x 720?) if not 1080i (1920 x 1080)
I'd say desktops for sure are at 1080i while smaller screen laptops (13" and below?) are still at 720
jusgoose
@gusd773
Mar 01 2018 17:12
@cmccormack i tried those but still got blurry pics
Christopher McCormack
@cmccormack
Mar 01 2018 17:13
@gusd773 do you have anything you can share?
jusgoose
@gusd773
Mar 01 2018 17:14
@cmccormack I've been google space pics using advance search for those same dimensions
Christopher McCormack
@cmccormack
Mar 01 2018 17:14
@gusd773 do you have anything you can share that shows it is blurry
Jason Luboff
@JLuboff
Mar 01 2018 17:15
You need to save the actual full size image and host it somewhere
The image doesn't even show for me
Christopher McCormack
@cmccormack
Mar 01 2018 17:16
yeah that's the thumb
Jason Luboff
@JLuboff
Mar 01 2018 17:16
Most websites don't allow you to take their image from their server and use it on your website (aka Hotlinking).
TIL MS SQL has a built in Compress/Decompress function
Simon Cordova
@gbsimon87
Mar 01 2018 17:20
Hey all, good aft! :)
Nate Mallison
@NJM8
Mar 01 2018 17:20
Anyone else having problems connecting to github?
Christopher McCormack
@cmccormack
Mar 01 2018 17:20
@gbsimon87 heya
@gusd773 check my fork does this look better to you? https://codepen.io/cmccormack/pen/paYoZv
Jason Luboff
@JLuboff
Mar 01 2018 17:21
@gbsimon87 Howdy
@NJM8 No, I'm able to get in
Simon Cordova
@gbsimon87
Mar 01 2018 17:21
What's up what's up!
Ken Haduch
@khaduch
Mar 01 2018 17:21
@cmccormack :point_up: March 1, 2018 11:43 AM - oh, yeah? I remember looking at that quite a long time ago, never used it on a project. I'll have to re-investigate that - color choice is not a skill that I have... :) thanks!
CamperBot
@camperbot
Mar 01 2018 17:21
khaduch sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1354 | @cmccormack |http://www.freecodecamp.org/cmccormack
Jason Luboff
@JLuboff
Mar 01 2018 17:23
@gbsimon87 Staying busy..you?
Christopher McCormack
@cmccormack
Mar 01 2018 17:26
@khaduch me neither :) there are some great resources out there for color though
jusgoose
@gusd773
Mar 01 2018 17:28
@cmccormack I tried that but it didn't work w my image it just went white page
for the background at least my text remained
Ken Haduch
@khaduch
Mar 01 2018 17:28
@gbsimon87 - hello Simon...
Christopher McCormack
@cmccormack
Mar 01 2018 17:30
@gusd773 did you save?
jusgoose
@gusd773
Mar 01 2018 17:31
@cmccormack yup I even removed the cover and no repeat extras I had
Jason Luboff
@JLuboff
Mar 01 2018 17:32
Most websites don't allow you to take their image from their server and use it on your website (aka Hotlinking).
You need to save the actual full size image and host it somewhere
Christopher McCormack
@cmccormack
Mar 01 2018 17:33
@gusd773 background: not background-image:
background: allows multiple background- options while background-image only 1 I believe
Simon Cordova
@gbsimon87
Mar 01 2018 17:33
Ahh, came to help out but actually need to get going
Night all! :)
Christopher McCormack
@cmccormack
Mar 01 2018 17:34
@gbsimon87 later
jusgoose
@gusd773
Mar 01 2018 17:36
@cmccormack It works but now it's repeating but when I remove the repeat it pixelates again
Christopher McCormack
@cmccormack
Mar 01 2018 17:37
@gusd773 it will pixelate because it's a tiny image, use a bigger image
jusgoose
@gusd773
Mar 01 2018 17:38
@cmccormack but I am using 1920X1080
Christopher McCormack
@cmccormack
Mar 01 2018 17:38
There simply isn't enough information in a small image to make it like sharp at higher resolutions. Some image editing tools will do some predictions and blurring to make it look slightly better, but really you need to just use a bigger image
you aren't your image is clearly tiny if you just follow the link https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTIpetfZPMQswPZ65DdckZkHAF3Ke5JRw0BbWk8BSI9i3p3UcZZww
It even says the size in the titlebar - 275x183
@gusd773 try popping my background in to yours and see what happens - https://mackville.net/wikipedia/images/wikipedia-down.png
jusgoose
@gusd773
Mar 01 2018 17:42
@cmccormack gotcha sorry I was just confused, ok so your image worked but I am now picking images that have the pixel dimesions that are huge viagoogle and still keep having the pixelation happen even at 7k X 4k
Christopher McCormack
@cmccormack
Mar 01 2018 17:42
you're probably not grabbing the correct link, maybe you're grabbing the thumbnail preview
jusgoose
@gusd773
Mar 01 2018 17:45
@cmccormack bangs head against wall thank you
CamperBot
@camperbot
Mar 01 2018 17:45
gusd773 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1355 | @cmccormack |http://www.freecodecamp.org/cmccormack
jusgoose
@gusd773
Mar 01 2018 17:45
I was doing exactly that wow I hate life
Christopher McCormack
@cmccormack
Mar 01 2018 17:46
@gusd773 :) I went ahead and broke out all of those additional options on background as well if you are interested:
  background-image: url("https://mackville.net/wikipedia/images/wikipedia-down.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
jusgoose
@gusd773
Mar 01 2018 17:46
@cmccormack does altering the background image attributes do the same stuff? or are you limited at that point
Christopher McCormack
@cmccormack
Mar 01 2018 17:47
Not sure what you mean. background can take several different attributes, while background-image can only take either none or the image url
jusgoose
@gusd773
Mar 01 2018 17:47
@cmccormack the options make it seem like you can do more than the part where add in stuff after the URL (ie "center center fix"
Christopher McCormack
@cmccormack
Mar 01 2018 17:48
@gusd773 read this through when you get a chance and try to make some sense of it. It's more complicated than I like but sort of explains it https://developer.mozilla.org/en-US/docs/Web/CSS/background
jusgoose
@gusd773
Mar 01 2018 17:48
    background: url("http://wallpapershome.com/images/wallpapers/earth-7251x4018-planet-space-10121.jpg")center center fixed;
that as opposed to adding in the options line by line
Christopher McCormack
@cmccormack
Mar 01 2018 17:52
I think you can do it like this:
background: url("https://mackville.net/wikipedia/images/wikipedia-down.png") fixed center/cover no-repeat;
but breaking it out is more readable

I actually didn't know about how to add cover to background until I read the link above :point_up: March 1, 2018 10:48 AM

The <bg-size> value may only be included immediately after <position>, separated with the '/' character, like this: "center/80%".

Gotta run for a few but hope that helped @gusd773 - remember the documentation can be extremely useful if you take the time to read it and practice with it
Onome Sotu
@onomesotu
Mar 01 2018 19:30
Hey guys, I'm grabbing at straws in the steamroller exercise in free code camp
Brad
@bradtaniguchi
Mar 01 2018 19:39
@onomesotu What you got so far? Are you close at least? or understand the approach you need to take? (recursive is usually the easiest)
Onome Sotu
@onomesotu
Mar 01 2018 19:39
yeah I am trying to use recursion
here is the code
it should work.. i just don't get it
function steamrollArray(arr) {
  var rolled = [];

  var recurs = (array) => {
    for(var i = 0; i < array.length; ++i){
      if(Array.isArray(array[i])){
        recurs(array[i]);
      } else {
        rolled.push(array[i]);
      }
    }
  }

  return rolled.reduce((a, b) => a.concat(b), []);
}

steamrollArray([[["a"]], [["b"]]]);
oh my God... I need a face punch
Jason Luboff
@JLuboff
Mar 01 2018 19:41
:facepunch:
there you go, face punch :P
Onome Sotu
@onomesotu
Mar 01 2018 19:41
I just saw that i wasn't calling recurs :worried:
@JLuboff Thanks .. i deserve at least two
CamperBot
@camperbot
Mar 01 2018 19:42
onomesotu sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2348 | @jluboff |http://www.freecodecamp.org/jluboff
Tanya
@tvasyleva
Mar 01 2018 19:44
hey guys im trying to wrap my head around scope in js and i was wondering if someone could help me explain something
Christopher McCormack
@cmccormack
Mar 01 2018 19:45
@tvasyleva we can try :)
Onome Sotu
@onomesotu
Mar 01 2018 19:45
@tvasyleva Have you read any material on it?
Brad
@bradtaniguchi
Mar 01 2018 19:46
@tvasyleva Now do you want the "classic" answer were you need to consider how varworks, this and general javascript. Or the cleaner "newer" answer were you can use `let, const', arrow functions and classes?
Tanya
@tvasyleva
Mar 01 2018 19:50
function changeAgeAndReference(person) {
    person.age = 25; //how come this will change age of person object passed
    person = { //but this doesnt change person object passed but its also not really creating a new global object
        name: 'John',
        age: 50
    };
     personb = { //declare a "global" variable 
        name: 'John2',
        age: 50
    };
     var personc = { //declare a local variable
        name: 'John3',
        age: 50
    };
      return person;
}
var personObj1 = {
    name: 'Alex',
    age: 30
};
var personObj2 = changeAgeAndReference(personObj1);
console.log(personObj1); // -> { name: 'Alex', age: 25 } changed aged from 30 to 25
console.log(personObj2); // -> { name: 'John', age: 50 } returns the new person object so obv its different
//console.log(person); <-- doesnt work! why????
console.log(personb); //works obviously because we declared as global
//console.log(personc); <--doesnt work obviously because we declared with var (local)
alright the question is how this person = in the function is treated- why is it treated like a local variable ?
Tanya
@tvasyleva
Mar 01 2018 19:55
@onomesotu yeah i read about the basics of var and this and let and then was trying to play around with some code since that's how i come to understand the concepts better and everything worked as expected until this ^
Brad
@bradtaniguchi
Mar 01 2018 19:55
@tvasyleva This looks to be more of a pass by reference thing than a scope thing.
When you pass a non-primitive value around in Javascript you pass its reference in memory.
This is why the age changes.
Pieter Stokkink
@forkerino
Mar 01 2018 19:56
@tvasyleva person starts out as a reference to the object passed into the function. That is why the first line changes a property of it. In the second line you create a new object and put a reference in person
Brad
@bradtaniguchi
Mar 01 2018 19:56
^
Pieter Stokkink
@forkerino
Mar 01 2018 19:57
and since you return it, that is what ends up in personObj2
Tanya
@tvasyleva
Mar 01 2018 19:58
yeah i understand why when you print out personObj1 it has age changed- it was passed by reference and instead of making a copy of the obj like i would in a pure function i just changed the obj
Pieter Stokkink
@forkerino
Mar 01 2018 19:58
yes
Tanya
@tvasyleva
Mar 01 2018 19:59
i guess i expected person = ... to also overwrite it because person was passed by reference
and then i saw that it created a new object instead and expected it to be global because it was done without var
Pieter Stokkink
@forkerino
Mar 01 2018 20:00
@tvasyleva because person is a function parameter, it will be similarly scoped as a local variable
Tanya
@tvasyleva
Mar 01 2018 20:01
@forkerino @bradtaniguchi thanks so much going to go try to wrap my head around that now
CamperBot
@camperbot
Mar 01 2018 20:01
tvasyleva sends brownie points to @forkerino and @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 403 | @bradtaniguchi |http://www.freecodecamp.org/bradtaniguchi
:star2: 2985 | @forkerino |http://www.freecodecamp.org/forkerino
Christopher McCormack
@cmccormack
Mar 01 2018 20:01
I think you can use global.person in your function if you want to test global @tvasyleva
Pieter Stokkink
@forkerino
Mar 01 2018 20:01
you're welcome
Christopher McCormack
@cmccormack
Mar 01 2018 20:01
(at least you can in node)
Markus Kiili
@Masd925
Mar 01 2018 20:02
@cmccormack window.person in the browser.
Jason Luboff
@JLuboff
Mar 01 2018 20:03
This conversation reminds me of the old days...
Christopher McCormack
@cmccormack
Mar 01 2018 20:03
I know where did the meaty questions go??
Brad
@bradtaniguchi
Mar 01 2018 20:03
@tvasyleva np, :D Javascripts difficulty lies in this sort of stuff, there's a lot of different cases
Markus Kiili
@Masd925
Mar 01 2018 20:03
No arguments here anymore. I miss them...
Tanya
@tvasyleva
Mar 01 2018 20:04
@bradtaniguchi yeah i previously learned a little c++ and it seems to have a lot less of those subtleties than js does and was much easier to debug :c
Markus Kiili
@Masd925
Mar 01 2018 20:04
Whether an object literal can contain JSON or not. Many hours of heated battle.
Jason Luboff
@JLuboff
Mar 01 2018 20:05
I hate when I forget to stringify my object results via console.log in node so then I have to restart the server lol (yes I'm using nodemon, but still takes a solid couple of seconds to restart)
Tanya
@tvasyleva
Mar 01 2018 20:05
@bradtaniguchi which is funny because js syntax looks so deceptively simple if you dont know any better youd think it was way easier than c++
Brad
@bradtaniguchi
Mar 01 2018 20:05
@tvasyleva Haha yea, well at least Javascript doesn't have pointers/memory management haha
Christopher McCormack
@cmccormack
Mar 01 2018 20:06
And in practice worrying about the scope of your variables in modern JS is almost not necessary
keep it as functional as possible and use const whenever possible
Brad
@bradtaniguchi
Mar 01 2018 20:07
@cmccormack If you can use all the fancy stuff, but its always good to know how the language works than relying on this new stuff
Christopher McCormack
@cmccormack
Mar 01 2018 20:07
That fancy stuff is part of the language now
because of those other issues
Brad
@bradtaniguchi
Mar 01 2018 20:07
The fact I still see const self = this; in my code does grind my gears tho
@cmccormack If its supported on your users browser, or you got babel setup.
Christopher McCormack
@cmccormack
Mar 01 2018 20:08
Because of React the only time I really make variables is doing something like const { id, items, className } = props or in this.state
Everything is supported if you have enough polyfills and a transpiler :)
Tanya
@tvasyleva
Mar 01 2018 20:19
one more noob question if you guys dont mind and then ill retire to study the literature..
//is there any difference between doing this:
function blabla(a){return a+4;}
//and this?
var blablaV2 = function(a){return a+4;};
//what about this?
blablaV3 = function(a){return a+4;};
//i's assume the last two would differ in scope if say they were inside another function or something, but what about the first one, if it was inside of another function would it be only able to be called in that local scope?
var blablaV4 = (a) => {return a+4;};
//i assume V4 is exactly same as V2 just in shorthand right?
Brad
@bradtaniguchi
Mar 01 2018 20:21
The last 2 are different in scope, the first two are more or less the same. (not too sure on the technical side of things, but day to day these are the same)
Aditya
@ezioda004
Mar 01 2018 20:23
First one is function declaration so it gets hoisted, others are function expression so they dont get hoisted.
Markus Kiili
@Masd925
Mar 01 2018 20:23
Variable declarations get hoisted but assignments not.
Tanya
@tvasyleva
Mar 01 2018 20:26
@ezioda004 ohhhh ok so i can use blabla before its place in code but not the other versions thanks so much that makes sense now. is there a function declaration shorthand as opposed to expression like v4?
CamperBot
@camperbot
Mar 01 2018 20:26
tvasyleva sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 488 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Tanya
@tvasyleva
Mar 01 2018 20:28
@Masd925 thanks, learning so much thanks to you guys!
CamperBot
@camperbot
Mar 01 2018 20:28
tvasyleva sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4711 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
Mar 01 2018 20:28
@tvasyleva It is not actually a shorthand, because arrow functions differ from those normal functions.
In general, there are differences. Here not.
Aditya
@ezioda004
Mar 01 2018 20:29
^ declaration is also one a kind, it doesnt have a shorthand
Tanya
@tvasyleva
Mar 01 2018 20:30
@Masd925 oh i thought it was a different way to write the same thing ill go read up on arrow functions then
Aditya
@ezioda004
Mar 01 2018 20:31
The main difference is the this keyword in =>, they go 1 scope up always
Stephen James
@sjames1958gm
Mar 01 2018 20:49
@tvasyleva Also, arrow functions have no arguments object
Jason Luboff
@JLuboff
Mar 01 2018 20:50
@sjames1958gm Didn't know that, good to know. Thanks
CamperBot
@camperbot
Mar 01 2018 20:50
jluboff sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9047 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Mar 01 2018 21:46
@JLuboff :+1: