Why do we increase depth of search for a mate detection in alpha beta pruning? I was following a tutorial for making a chess engine and in that, while writing the alpha beta pruning function the tutorial before checking for all possible moves generated , checks weather the current side is in check or not. If in check the depth was increased and i couldn't understand the reason. I am fairly new to chess engine programming and have searched about this but couldn't find anything relevant.
Any help will be much appreciated.Thanks.

Here is the code for alpha beta pruning.

function AlphaBeta(depth, alpha, beta)
{
    SearchController.nodes++;
    if (depth &lt;= 0)
    {
        return Evaluate();
    }

    //fiftyMove rule or if a position is Repeated
    if ((IsRepeated() || GameBoard.fiftyMove &gt;= 100) &amp;&amp; GameBoard.hisPly != 0)
        return 0;

    if (GameBoard.ply &gt; MAXDEPTH - 1 )
        return Evaluate();

    //this is the line i am talking about
    var InCheck = SqAttacked(GameBoard.pieceList[Kings[GameBoard.side] * 10] , GameBoard.side ^ 1 );
    if (InCheck)  {
        depth++; //&lt;---------HERE
    }

    var score = -INFINITE;

    GenerateMoves();

    var Move = NOMOVE, MoveNum = 0, BestMove = NOMOVE;
    var legal = 0; // To see weather any legal moves are possible
    var start = GameBoard.moveListStart[GameBoard.ply], end = GameBoard.moveListStart[GameBoard.ply + 1];

    for(MoveNum = start; MoveNum &lt; end; MoveNum++)
    {
        Move = GameBoard.moveList[MoveNum];

        if (!MakeMove(Move))
            continue;

        legal++;

        score = -AlphaBeta(depth - 1, -beta, -alpha);

        TakeMoveBack();


        if (score &gt; alpha)
        {
            if(score &gt;= beta)
                return beta;

            alpha = score;
            BestMove = Move;
        }

        console.log('For move : ' + PrMove(Move) + ' Score : ' + score );
    }

    if (BestMove != NOMOVE)
    {
        StorePvMove(BestMove);
    }

    if (legal == 0)
    {
        if (SqAttacked(GameBoard.pieceList[Kings[GameBoard.side] * 10] , GameBoard.side ^ 1))
        {
            return MATE - GameBoard.ply;
        }
        else return 0;
    }

    console.log("");
    console.log("Best Move at Height : " + depth + ' Move : ' + PrMove(BestMove) + ' Score : ' + alpha);
    return alpha;

}
I can see more than one reason for that.

One reason is that after a check there are very few moves available: usually there are 30 moves available, but after a check there are usually at most 4 or 5. So that move doesn't count as a full ply if you want to measure the size of the resulting tree, and in the same search time you can go deeper.  

Another reason, and I think it is the most important, is that a check is a forcing move, and consequences of a forcing move must be considered more deeply. So it is good to go deeper after a check.

Note that in this way, the program will tend to analyze all forced sequences of consecutive checks very deep, in this way it can easily find all perpetual checks and many forced mates. So this is can be very useful.