Code Block

noun

say it: “KOHD blok” /koʊd blɒk/

Several lines of code grouped together so they run as one unit. In JavaScript a block sits between curly braces, { and }.

What is a Code Block?

A Block of code is 1 or more lines of code grouped together as a logical unit. The gode is grouped because it logically belongs together and should be executed at the same time.

Some languages use {} to create a block - i.e. JavaScript, Java, C#

//Java
public int add(int left, int right) {
    // everything between {} is a block
    return left + right;
}
//C#
public int Add(int left, int right) 
{
    return left + right;
}
//JavaScript
function add(left, right) {
    return left + right;
}

Some languages use indentation to create blocks - such as Python

def add(left, right):
    # everything indented is a block
    return left + right

In a sentence

  • “Everything inside the curly braces is one code block, so all three lines run when the order qualifies.”

Level: Novice · More General terms at this level

Updated