Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Creating class and objects in plain or classic JavaScript

In ECMAScript6(ES6) JavaScript Classes introduced and JavaScript Classes are templates or blueprint for JavaScript Objects.

Note: JavaScript can function as both a procedural and an object-oriented language.

Code example

//Class or blueprint 
class Car {
    constructor(name, model, year, cartype) {
        this.Name = name;
        this.Model = model;
        this.Year = year;
        this.CarType = cartype;
    GetSafetyDetails() {
        var details = "Global NCAP 5-star rating in adult occupant";
        details += " 4-star in child safety, making it the top safest car";
        return details;


//real world instance(object) of car class or blueprint
let mahindraXUV300 = new Car("Mahindra XUV300", "XUV300 W8 Diesel", "2019", "SUV");

View without layout in MVC

If you want to show view without any surrounding _Layout page, you can set Layout=null.

Code sample,

With following custom error view, you displayed without surrounding _Layout page.

    Layout = null;
<div class="alert alert-danger alert-dismissible fade show">
        <h5>Error! </h5>
        <h6>Something went wrong, contact admin, or try again</h6>

Exception handling for document ready in jQuery

Errors in their jQuery $(document).ready function breaks page or prevent executing important code, You can avoid this with simple try..catch approach

Code example

$(document).ready(function () {
try {
  //your all JavaScript/jQuery code
} catch (error) {
    // handle error
    //Default code when error/or exception this will execute