My line of code dont work why using oncollisionenter2d

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public float damageTaken;
    // Update is called once per frame
    void Update()
    {
        Debug.Log(damageTaken);
    }
    private void Start()
    {
        
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.transform.tag == "Enemy")
        {
            
            Destroy(gameObject);
            damageTaken += 1;
            Debug.Log("hit enemy");
            
        }
    }
}

when the collision enter , the debug.log(“hit enemy”) executes but the damage taken doesnt +1 and constantly stay at 0.

You are destroying the object. When you destroy the object the script stops. Think about using this variable damageTaken in the enemy script for example, instead of in the bullet script.