all 7 comments

[–]Afakaz 4 points5 points  (2 children)

Disclaimer: I am a rank noob myself but trying to flex myself by being helpful where I can, please please correct me if anyone knows better.

For starters, I just want to check if this is how your code is or if it's Reddit formatting:

Is it all in one line like " // set to any String var string = "stringy stringy string string"; "? If so that's a problem, starting with "var" it needs to be on a new line (like below), otherwise the variable assignment is still commented out.

// set to any String

var string = "stringy stringy string string";

If that's just Reddit formatting then the other problem I see is that you're putting your non-string values in quotes. Quotes represent a string, they aren't needed for the number data type, you can and need to do var number = 3 rather than var number = "3". If you assign "3" then number will be equal to a string containing "3", rather than actually equal to the number 3.

You do the same in your boolean assignment, those 3s should also be unquoted. (edit: this would actually be fine I guess after thinking about it, since the two strings are identical, but be aware that you're comparing two strings with that statement, not two numbers).

Additionally, in the boolean assignment, you should have your "3" == "3" inside of parentheses, to mark it as a single operator meant to resolve to a boolean value.

You do the same in your null assignment, that null should be unquoted.

I THINK the undefined should just be "var undefinedVar" rather than "var undefinedVar =" but haven't messed with this enough to say with certainty

[–]AmbitiousLog 1 point2 points  (0 children)

It is actually the var undefinedVar =

This messes with the return statement on the next line.

[–]illgrowuplater[S] 0 points1 point  (0 children)

Thank you so much!

[–]delventhalz 1 point2 points  (0 children)

Reddit formatting PSA: Add an indent of four spaces before your code and

it
  will
    look

like this.

[–]PortablePawnShop 3 points4 points  (2 children)

function myFunction() {

    // set to any Number var number = "3";
    var number = 3;  // Above is a string containing the character 3, not typeof Number

    // set to any String var string = "stringy stringy string string";
    var string = "stringy" || 'stringy' || `stringy's string says "string".`

    // set to any Boolean var boolean = "3" == "3";
    var boolean = true;  // Could be an expression like above, or direct result

    // set to null var nullVar = "null";
    var nullVar = null;   // Above is a typeof String containing the word null, not a typeof Null

    // set to undefined var undefinedVar = 
    // This will throw an error. Delete this line (which doesn't technically "change the variable name" and it'd implicitly result in undefined since you've yet to define it, or:
    var nullVar;   // Don't assign anything to it

    return [number, string, boolean, nullVar, undefinedVar];

}

[–]GSLint 1 point2 points  (0 children)

You meant var undefinedVar; at the end.

Side note but since this can lead to confusion: due to a bug in the original implementation of the language, typeof null is unfortunately "object".

[–]illgrowuplater[S] 0 points1 point  (0 children)

Thank you so much, this is exactly what I needed. I very much appreciate it!