Yes, it is compulsory for you to give a legal notice before leaving your job . The notice period is generally of 3 months. However, the notice period can differ from Company to Company dependent upon their employment policies.
If you do not serve a notice in regards to leaving your job, there can be Court proceedings against you on the grounds of breach of contract or employment agreement. A notice period gives time to the Company to find another employee in your position so that the work is not hampered. Salaries also differ during a notice period. Thus, you must always serve a notice. If you are stuck in a case where you haven’t served a notice and left your job you can find a good lawyer online to defend your case.