Javatpoint Logo
Javatpoint Logo

What is a Bracket?

Brackets are part of many programming languages that denote the blocks of code. The brackets are also known as square brackets and are used as a punctuation mark in grammar. Whenever the opening square bracket is created, then you must create a closing square bracket at the end.

The opening square bracket and closing square bracket are the two different types of brackets. When the opening edges facing are toward the right, it is called the opening square bracket "[". Else when the opening edges are facing towards the left, it is called the closing square bracket "]".

The brackets and curly braces are found on the QWERTY keyboard. The opening and closing brackets are located adjacent to each other on the same line.

A more clear and detailed explanation is given on the square brackets in the following side headings.

  • Location of square brackets on the keyboard
  • Designing open and closed brackets
  • Where do we use these brackets?
  • Are there any symbols along with the square brackets?

Location of square brackets on the keyboard

The square brackets are on the keyboard's right side of the "P" key. In the below figure, the brackets are marked in red.

What is a Bracket

How to create an open and close square bracket

By using the QWERTY and English keyboards, the open and close square brackets are created by pressing the keys dedicated to opening and closing brackets. The keys for open and closed square brackets and the curly brackets are present on the keyboard.

When you press and hold the shift key on the keyboard and then press the bracket keys, the curly brackets "{ }"are created.

Creating the open and close square brackets using the shortcut on Windows

  • To create the opening bracket "[" press and hold the "Alt" key and press the number keys 0 9 1 one after the other simultaneously.
  • To create the closing bracket "]", press and hold the "Alt" key and press the number keys 0, 9 3 one after the other simultaneously.

Creating the open and close brackets using the shortcut on MacBook or Apple

  • To create the opening bracket "[" press and hold the "Alt" key and press the "Shift" key and "(" one after the other simultaneously.
  • To create the opening bracket "[" press and hold the "Alt" key and press the "Shift" key and ")" one after the other simultaneously.

Designing the open and close brackets on the smartphone and tablet keyboard

  • To create the square brackets using the mobile phone or tablet keyboard, click on the numbers (123) key as shown in the figure below.
What is a Bracket
  • Click on the sym or symbols (# + =) key.
    What is a Bracket
  • Finally, click on the "[" or "]" key to create the square brackets.
    What is a Bracket

What should we do if the numeric keypad is absent on the keyboard?

  • If a numeric keypad is not present on your keyboard, you have to activate the Num Lock function or press the Fn + Num Lock key.
  • If a Num Lock key is also absent on your keyboard, press the "Fn" key first and then combine Alt with the keys mentioned earlier.
  • If you can still not make the brackets symbol, you can copy them from this article and paste them at your chosen location.

How are brackets used?

English

  • In English, while we write or type any topic, we use brackets to write the comments or give any extra information and examples.

Programming

  • In programming languages, square brackets are used to create arrays and indexing.
  • In accessing the elements of strings and arrays, square brackets are also used.
  • The square brackets are used in regular expressions, and in SQL, they denote constraints like primary key, etc. In JavaScript, C#, the brackets are used to evaluate the string and match the patterns.
  • Example for brackets in SQL
  • Example for brackets in JavaScript

In the above example in JavaScript, the brackets are used with the variable student in taking inputs for a particular index of an array.

  • Example for brackets in Regular Expression

In the above example, in the $gain variable, the characters ranging in 'a' through 'm' are replaced by a hyphen.

Mathematics

  • In mathematics, the brackets are used to denote the intervals, floor functions, and sub-expressions.

Are there any symbols along with the square brackets?

Yes, curly brackets are present along with the square brackets in the English keyboards.


Next TopicWhat is Burp Suite





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA