Can someone explain this code line to me?

Discussion in 'Javascript' started by effendi, Apr 3, 2005.

  1. effendi

    effendi Guest

    Hi everyone, I am relatively new to JS and I am hoping someone could
    tell me what this line of codes mean. This was written by some
    brilliant guys at webfx and I am trying to understand some of their

    To begin with I don't understand how this variable is set.

    var sliderE1=document.getElementByID?
    document.getElementById("slider-1"): null;

    Question 1: What is the function of the "?" mark after the
    Question 2: What is the reason for including ": null"
    and Question 3: Can't this be done just by simply using

    Thanks in advance.
    effendi, Apr 3, 2005
    1. Advertisements

  2. effendi

    Evertjan. Guest

    wrote on 03 apr 2005 in comp.lang.javascript:
    var condition = false
    var a = (condition) ? "This is true" : "This however is false"

    will show: This however is false

    var condition = true
    var a = (condition) ? "This is true" : "This however is false"

    will show: This is true


    is only true in browsers that support it.
    in other [read older] browsers:

    var sliderE1 = document.getElementById("slider-1")

    would give an error and the js would stop.


    Your first questions are so basic,
    that I suppose you did not read any javascript tutorial before asking.

    Evertjan., Apr 3, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.