Skip to content

Commit

Permalink
Featured: 10 move questions
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly.basaraba committed Feb 18, 2025
1 parent 0bf49b3 commit c22a10c
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions question.json
Original file line number Diff line number Diff line change
Expand Up @@ -4638,5 +4638,85 @@
"level": "advanced",
"theme": "Protractor, Headless Testing",
"text": "### How do you run Protractor tests in headless mode?\n\nTo run Protractor tests in headless mode, you can configure the `protractor.conf.js` file to use a headless browser like Chrome.\n\nExample configuration:\n\n```javascript\ncapabilities: {\n 'browserName': 'chrome',\n 'chromeOptions': {\n args: ['--headless', '--disable-gpu', '--window-size=800x600']\n }\n},\n```"
},
{
"link": "#how-to-catch-errors-in-promises",
"title": "How to catch errors in Promises",
"url": "",
"level": "beginner",
"theme": "JavaScript, Promises, Error Handling",
"text": "### How to catch errors in Promises\n\nYou can handle errors in promises by appending a `.catch()` method to the promise chain.\n\n```javascript\nfetch('https://api.example.com/data')\n .then(response => response.json())\n .then(data => console.log(data))\n .catch(error => console.error('Error:', error));\n```"
},
{
"link": "#how-to-catch-errors-in-async-await",
"title": "How to catch errors in async/await",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Async/Await, Error Handling",
"text": "### How to catch errors in async/await\n\nWrap your async code in a try/catch block to handle errors gracefully.\n\n```javascript\nasync function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error:', error);\n }\n}\nfetchData();\n```"
},
{
"link": "#how-to-catch-errors-in-synchronous-code",
"title": "How to catch errors in synchronous code",
"url": "",
"level": "beginner",
"theme": "JavaScript, Error Handling",
"text": "### How to catch errors in synchronous code\n\nFor synchronous operations, use a try/catch block to handle errors.\n\n```javascript\ntry {\n const result = riskyOperation();\n console.log(result);\n} catch (error) {\n console.error('Caught an error:', error);\n}\n```"
},
{
"link": "#how-to-catch-errors-in-event-handlers",
"title": "How to catch errors in event handlers",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Error Handling, Events",
"text": "### How to catch errors in event handlers\n\nWrap event handler code in a try/catch block to ensure errors do not crash the application.\n\n```javascript\ndocument.getElementById('myButton').addEventListener('click', () => {\n try {\n // Code that might throw an error\n performAction();\n } catch (error) {\n console.error('Error during click event:', error);\n }\n});\n```"
},
{
"link": "#how-to-catch-errors-with-fetch-api",
"title": "How to catch errors with the Fetch API",
"url": "",
"level": "beginner",
"theme": "JavaScript, Fetch API, Error Handling",
"text": "### How to catch errors with the Fetch API\n\nUse `.catch()` to handle errors when making HTTP requests with the Fetch API.\n\n```javascript\nfetch('https://api.example.com/data')\n .then(response => {\n if (!response.ok) {\n throw new Error('Network response was not ok');\n }\n return response.json();\n })\n .then(data => console.log(data))\n .catch(error => console.error('Fetch error:', error));\n```"
},
{
"link": "#how-to-catch-errors-in-nodejs",
"title": "How to catch errors in Node.js",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Node.js, Error Handling",
"text": "### How to catch errors in Node.js\n\nIn Node.js, use try/catch for synchronous code and attach error listeners for asynchronous code.\n\n```javascript\n// Synchronous error handling\ntry {\n const data = fs.readFileSync('/path/to/file');\n console.log(data);\n} catch (error) {\n console.error('Error reading file:', error);\n}\n\n// Asynchronous error handling\nfs.readFile('/path/to/file', (error, data) => {\n if (error) {\n return console.error('Error reading file:', error);\n }\n console.log(data);\n});\n```"
},
{
"link": "#how-to-catch-errors-in-callbacks",
"title": "How to catch errors in callbacks",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Callbacks, Error Handling",
"text": "### How to catch errors in callbacks\n\nWhen working with callbacks, ensure that errors are passed as the first argument to the callback function.\n\n```javascript\nfunction performAsyncOperation(callback) {\n // Simulate error\n const error = new Error('Something went wrong');\n callback(error, null);\n}\n\nperformAsyncOperation((error, result) => {\n if (error) {\n return console.error('Callback error:', error);\n }\n console.log(result);\n});\n```"
},
{
"link": "#how-to-use-global-error-handling-with-try-catch",
"title": "How to use global error handling with try/catch",
"url": "",
"level": "advanced",
"theme": "JavaScript, Error Handling",
"text": "### How to use global error handling with try/catch\n\nFor comprehensive error handling, set up global error listeners in your application.\n\n```javascript\nwindow.onerror = function(message, source, lineno, colno, error) {\n console.error('Global error caught:', message, 'at', source + ':' + lineno + ':' + colno);\n};\n\n// Example triggering a global error\nnonExistentFunction();\n```"
},
{
"link": "#how-to-catch-errors-in-expressjs",
"title": "How to catch errors in Express.js",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Express.js, Error Handling",
"text": "### How to catch errors in Express.js\n\nUse middleware to catch and handle errors in your Express applications.\n\n```javascript\nconst express = require('express');\nconst app = express();\n\n// Your routes here\napp.get('/', (req, res) => {\n throw new Error('Oops!');\n});\n\n// Error handling middleware\napp.use((err, req, res, next) => {\n console.error(err.stack);\n res.status(500).send('Something broke!');\n});\n\napp.listen(3000, () => console.log('Server running on port 3000'));\n```"
},
{
"link": "#how-to-catch-unhandled-rejections",
"title": "How to catch unhandled promise rejections",
"url": "",
"level": "advanced",
"theme": "JavaScript, Promises, Error Handling",
"text": "### How to catch unhandled promise rejections\n\nListen for unhandled promise rejections to prevent unexpected application crashes.\n\n```javascript\nprocess.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n});\n\n// Example of an unhandled rejection\nPromise.reject(new Error('Unhandled error'));\n```"
}
]

0 comments on commit c22a10c

Please sign in to comment.