Is possible to set cookies via ajax?

I am learning how to use Yii 2, and in the progress of developing a project, i got to the need of use for cookies, but the actions i am requesting are via ajax, there are some data that have to be stored in cookie storage, so my question is if there is a way to store cookie data via ajax with yii 2, and if that is possible, is there a way to make javascript to read this data? i know the data will be encrypted by yii, i’m just curious about that

Cookies are held in the browser and are therefore available in javascript. Google javascript Cookie or this might help:

You could also look at LocalStorage, a more modern alternative to using cookies