learning-zone / javascript-basics

JavaScript Basics
https://learning-zone.github.io/javascript-basics/
1.75k stars 616 forks source link

Wrong example in Regex Pattern section #12

Closed wellitongervickas closed 3 years ago

wellitongervickas commented 3 years ago

On this page: https://github.com/learning-zone/javascript-interview-questions We have a section called "Q. What is the purpose of exec method?" with code below:

var pattern = /you/;
console.log(pattern.test("How are you?")); //you

Is it "exec" instead "test" ?

var pattern = /you/;
console.log(pattern.exec("How are you?")); // ["you", index: 8, input: "How are you?", groups: undefined]

Q. What is the purpose of seal method? We have:

const object = {
    property: 'Welcome JS world'
};
Object.freeze(object);
object.property = 'Welcome to object world';
console.log(Object.isFrozen(object)); // Welcome to object world
delete object.property; // You cannot delete when sealed
console.log(object.property); //Welcome to object world

Maybe:

const object = {
    property: 'Welcome JS world'
};
Object.seal(object);
object.property = 'Welcome to object world';
console.log(Object.isSealed(object)); // true
delete object.property; // You cannot delete when sealed
console.log(object.property); //Welcome to object world
learning-zone commented 3 years ago

Thanks for pointing out. Both the answers are updated with correct example.