diff --git a/src/data/question-groups/javascript/content/prevent-default.md b/src/data/question-groups/javascript/content/prevent-default.md new file mode 100644 index 000000000..cc721bac1 --- /dev/null +++ b/src/data/question-groups/javascript/content/prevent-default.md @@ -0,0 +1,10 @@ +The `event.preventDefault()` method is used to prevent the default action of an event. For example, when you click on a link, the default action is to navigate to the link's URL. But, if you want to prevent the navigation, you can use `event.preventDefault()` method. + +```js +const link = document.querySelector('a'); + +link.addEventListener('click', (event) => { + event.preventDefault(); + console.log('Clicked on link!'); +}); +``` diff --git a/src/data/question-groups/javascript/javascript.md b/src/data/question-groups/javascript/javascript.md index 654c3a5cc..2cca02bff 100644 --- a/src/data/question-groups/javascript/javascript.md +++ b/src/data/question-groups/javascript/javascript.md @@ -168,4 +168,14 @@ questions: topics: - 'Core' - 'Intermediate' + - question: Is Java and JavaScript the same? + answer: No, Java and JavaScript are distinct languages. Their similarity in name is coincidental, much like `car` and `carpet`. Java is often used for backend and mobile apps, while JavaScript powers web interactivity and backend. + topics: + - 'Core' + - 'Beginner' + - question: What is `preventDefault()` method in JavaScript? + answer: prevent-default.md + topics: + - 'Core' + - 'Intermediate' ---