Default value

2 snippets across 2 stacks — React, SQL

Also written as default values

REReact

Default Prop Values

RE · Components
syntax
function Component({ propA = defaultValue }) { ... }
example
function Badge({ label = "Member", color = "gray" }) {
  return (
    <span style={{ backgroundColor: color }}>
      {label}
    </span>
  );
}

// Uses defaults
<Badge />
// Overrides
<Badge label="Admin" color="crimson" />
output
First renders "Member" with gray background. Second renders "Admin" with crimson.

Note Use default parameter values in the destructuring rather than the legacy defaultProps static property, which is deprecated in React 19.

SQLSQL

DEFAULT Values

SQL · Table Operations
syntax
column_name type DEFAULT value
example
CREATE TABLE tasks (
  id SERIAL PRIMARY KEY,
  title VARCHAR(200) NOT NULL,
  status VARCHAR(20) DEFAULT 'pending',
  priority INTEGER DEFAULT 0,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
output
-- Omitting status, priority, or created_at uses defaults

Note DEFAULT applies only when the column is omitted from INSERT. Explicitly inserting NULL overrides the default with NULL (unless NOT NULL is also set). You can use expressions like CURRENT_TIMESTAMP as defaults.