Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:57:09+00:00 2026-06-13T19:57:09+00:00

AS the title says I am trying to check whether a variable is defined

  • 0

AS the title says I am trying to check whether a variable is defined in SASS. (I am using compass if that makes any different difference)

I’ve found the Ruby equivalent which is:

defined? foo

Gave that a shot in the dark but it just gave me the error:

defined": expected "{", was "?

I’ve found a work around (which is obviously just to define the variable in all cases, which in this case it actually makes more sense) but I’d really like to know if this is possible for the future

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:57:10+00:00Added an answer on June 13, 2026 at 7:57 pm

    For Sass 3.3 and later

    As of Sass 3.3 there is a variable-exists() function. From the changelog:

    • It is now possible to determine the existence of different Sass constructs using these new functions:
      • variable-exists($name) checks if a variable resolves in the current scope.
      • global-variable-exists($name) checks if a global variable of the given name exists.
        …

    Example usage:

    $some_variable: 5;
    @if variable-exists(some_variable) {
        /* I get output to the CSS file */
    }
    @if variable-exists(nonexistent_variable) {
        /* But I don't */
    }
    

    For Sass 3.2.x and earlier (my original answer)

    I ran into the same problem today: trying to check if a variable is set, and if so adding a style, using a mixin, etc.

    After reading that an isset() function isn’t going to be added to sass, I found a simple workaround using the !default keyword:

    @mixin my_mixin() {
      // Set the variable to false only if it's not already set.
      $base-color: false !default;
    
      // Check the guaranteed-existing variable. If it didn't exist 
      // before calling this mixin/function/whatever, this will 
      // return false.
      @if $base-color {
         color: $base-color;
      }
    }
    

    If false is a valid value for your variable, you can use:

    @mixin my_mixin() {
      $base-color: null !default;
    
      @if $base-color != null {
         color: $base-color;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, I'm trying to create a UIImage that will go inside
Like the title says, I'm trying to find elements of M that exist in
As the title says im trying to load Facebook profile images into flash using
Like the title says I am trying to create some regex that selects anything
I'm trying to do what the title says. I've seen that font-size can be
As the title says, I'm trying to create a web page that allows admins
As the title says, I'm trying to populate the properties of an object using
Just as the title says, I'm trying to create a script that will take
like the title says, I am trying to create a drop down menu using
As the title says, I'm trying to change the ID of all elements with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.