dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: Question regarding comparison operators

  1. #1
    Join Date
    Jul 2014
    Posts
    3

    Question regarding comparison operators

    Hello all,

    I hope you can help me.

    I was given the following code:

    var o = { a: 1, b: "1.0", c: false, d: true };
    var a = "b";

    ... and they wanted the results to the following:

    o.a ==> 1
    o[ a ] ==> 1.0

    Now, I understand that this an equal to or greater situation, but when I run it in console I get a syntax error. Everything I have read says that javascript uses ' <= ' and ' >= " not the double equal sign with the greater than or less than. Am I crazy?

    They also tossed this out ..
    o.a == o.b ==> true

    This too generated a syntax error and when I adjusted it to a => I get a ReferenceError, left-hand side in assignment error.

    Could somebody shed some light on this. Are these 'accurate' queries and I just don't know what I am doing or are these queries written wrong?

    Thanks

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Take a look at:
    https://developer.mozilla.org/en-US/..._and_Operators

    Btw: . and [ ] are the property access expressions. So, o.a is equal to o[a]. There are some important distinctions between those two, though.
    Last edited by tech_soul8; 07-31-2014 at 05:06 PM.

  3. #3
    Join Date
    Jul 2014
    Posts
    4
    Maybe you should check with the original source to see if perhaps they're showing you a typo (unless they're wanting you to be able to identify what an invalid expression is vs a valid one).

    In other words:

    o.a ==> 1 (INVALID; result is SyntaxError)
    o.a == 1 (VALID; result is true)

    o[a] ==> 1.0 (INVALID; result is SyntaxError)
    o[a] == 1.0 (VALID; result is true)

    o.a == o.b ==> true (INVALID; result is SyntaxError)
    o.a == o.b == true (VALID; result is true)

  4. #4
    Join Date
    Jul 2014
    Posts
    3
    Quote Originally Posted by mborja View Post
    Maybe you should check with the original source to see if perhaps they're showing you a typo (unless they're wanting you to be able to identify what an invalid expression is vs a valid one).

    In other words:

    o.a ==> 1 (INVALID; result is SyntaxError)
    o.a == 1 (VALID; result is true)

    o[a] ==> 1.0 (INVALID; result is SyntaxError)
    o[a] == 1.0 (VALID; result is true)

    o.a == o.b ==> true (INVALID; result is SyntaxError)
    o.a == o.b == true (VALID; result is true)


    See .. that's what I am really wondering. Every question is a syntax error but I get what they're trying to ask. So .. I don't know if I should answer what I 'THINK' would be what they want OR just point out each is a syntax error. Ugg .. this sucks. I guess I could put down both. Thanks for looking at this.

  5. #5
    Join Date
    Nov 2010
    Posts
    1,099
    judging from the instructions, I would say that they are using ==> not as code, but as shorthand to mean "should return".

    so o.a should return 1 (which it will)
    var a = "b";
    o[a] should return 1.0 (which it will)

    etc

    Confusing, but hey - given some of the stuff they teach in javascript courses these days, hardly surprising

  6. #6
    Who is "they" -- it sounds like "they" don't know the first blasted thing about programming.

    Lemme guess, an "educator"? That whole "you must be in college to encounter something this stupid"

    Your not nuts -- "they" are, theres no such thing as ==>

  7. #7
    Join Date
    Jul 2014
    Posts
    3

    Cool

    Quote Originally Posted by xelawho View Post
    judging from the instructions, I would say that they are using ==> not as code, but as shorthand to mean "should return".

    so o.a should return 1 (which it will)
    var a = "b";
    o[a] should return 1.0 (which it will)

    etc

    Confusing, but hey - given some of the stuff they teach in javascript courses these days, hardly surprising

    So .. last night it hit me. "==>" is an arrow pointing to the result. So, it seems I was provided with a portion of my skills test with the answers already provided. Now .. choosing comparison operators to indicate an arrow would not be my first choice, but this has got to be the answers.

    So .. I will provide them with the answers, point out the fact that they included the answers, that I checked their work, and they are all correct.

    Thanks for looking, guys.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles