Ratings can also help you prioritize content improvements. For example, if three of the shortest articles in a library show high ratings, you might decide to break up the longer articles into shorter ones that target more specific topics.

In order to allow library visitors and contributors to rate library items, and to encourage interaction, ratings must be turned on for the library. Typically, if you own or manage the library, you can do this easily. You can choose whether to let library visitors apply a star rating to an item (one to five stars) or to simply ”like” the item.

To enable rating refer this article

Code to update like:

function setLike(likeFlag) {
     SP.SOD.registerSod('reputation.js', '/_layouts/15/reputation.js');
     SP.SOD.executeFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function() {
         SP.SOD.executeFunc('sp.js', 'SP.ClientContext', UpdateLike(likeFlag));
     });
 }

 function UpdateLike(likeFlag) {
     var listId = "6d9e46c2-b396-4a4f-bc1f-6e265dfb6fe6"; //set list id and make sure rating is enabled in the list 
     var itemId = 3; //List Item Id 
     var ctx = new SP.ClientContext.get\ _current();
     Microsoft.Office.Server.ReputationModel.Reputation.setLike(ctx, listId, itemId, likeFlag);
     ctx.executeQueryAsync(Function.createDelegate(this, this.RatingSuccess), Function.createDelegate(this, this.RatingFailure));
 }

 function RatingSuccess(sender, args) {
     alert('Rating updated successfully');
 }

 function RatingFailure(sender, args) {
     alert('Failed:' + args.get\ _message());
 }
 
<button onclick="setLike(true)">Like</button>
<button onclick="setLike(false)">Unlike</button>