CodeBlanks Logo Icon CodeBlanks

Adding comments

Learn to add line comments to a PR.

What is an inline comment?

During a GitHub Pull Request review, you can add a comment directly to a specific code line. This comment is not just a general message; it is linked to the relevant line and clearly shows where the issue is located.

function divide(a, b) {
    return a / b;
}

For example, if you notice a possible division by zero, you can leave a comment directly on the return a / b; line.

Adding comments and suggestions

In a line comment, you can explain an issue and suggest how the code should be changed. GitHub also provides a suggestion feature in its supported review interface that allows proposed code changes to be applied directly.

// Suggested validation
if (b === 0) {
    throw new Error("Cannot divide by zero");
}

Keep comments concise, clear, and solution-oriented.

Practice Create inline comment data

Create an object named comment. Set line to 8, type to "inline", and suggestion to "Add validation". Print the suggestion using console.log.

Starter code

terminal
const comment = {
    // Yorum bilgilerini ekle
};

// Öneriyi yazdır

Sample solution

terminal
const comment = {
    line: 8,
    type: "inline",
    suggestion: "Add validation"
};

console.log(comment.suggestion);

Expected output

Add validation

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which type of comment is used to provide direct feedback on a code line?

  • Commit message
  • Repository description
  • Inline comment Correct answer
  • General PR description

Explanation: An inline comment is attached to a specific code line in a Pull Request.

2 Specify the comment type

Question
const comment = {
    line: 12,
    type: "____"
};
Answer
const comment = {
    line: 12,
    type: "inline"
};

Explanation: A comment attached to a specific code line is called inline.

3 PR comment features

Term Meaning
Inline Attached to a specific line
Comment A feedback message
Suggestion A proposed code change
Line A line of code

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow