Advanced Web Programming (AWP) Exam - University Ferhat Abbas Setif - January 2024 PDF
Document Details
Uploaded by EasyToUseDarmstadtium9811
Université Ferhat Abbas Sétif
2024
Tags
Summary
This is an advanced web programming exam from University Ferhat Abbas Setif, taken on January 21, 2024. The document is a PDF exam paper, including multiple-choice questions and exercises related to web development, JavaScript, AJAX, and promises.
Full Transcript
University Ferhat Abbas Setif 1 Department of Computer Science Sunday, January 21, 2024 Advanced Web Programming (AWP) Exam First name: last name: group:...
University Ferhat Abbas Setif 1 Department of Computer Science Sunday, January 21, 2024 Advanced Web Programming (AWP) Exam First name: last name: group: Multiple Choice Questions (MCQ): (0.75 correct answer, -0.5 wrong answer, 0 if you don’t answer a question) 1) What is true about Ajax? 9) Which keyword is used to declare block-scoped a) AJAX is a web development technique for variables in JavaScript? creating interactive web applications. a) var b) Ajax update a web page without reloading the b) let page c) const c) Ajax request data from a server after the page d) variable has loaded 10) What will be the output of the following code? d) All of the above function delayLog() { 2) Which of the following feature makes the Ajax for (var i = 1; i x)('I love')} programming`); a) It executes the code of JavaScript a) I love programming b) It creates separate threads for asynchronous b) undefined programming tasks to run c) ${(x => x)('I love') programming c) It checks for the call stack and pushes callbacks d) TypeError from the callback queue 6) What will be the output of: d) It sets timer for setTimeout() Promise.resolve(5); 13) Javascript is a multithreaded language a) 5 a) True b) Promise {: 5} b) False c) Promise {: 5} 14) What is the role of the onreadystatechange event in d) Error AJAX? 7) What will be the output of: a) To specify the URL of the server async function getData() { b) To specify the request data sent to the server return await Promise.resolve('I made it!'); c) To specify the response data received from the } server const data = getData(); d) To specify the function to be executed when the console.log(data); AJAX request status changes a) "I made it!" 15) What is a "closure" in JavaScript? b) Promise {: "I made it!"} a) A function that is stored as a property of an c) Promise {} object. d) Undefined b) A function that can be accessed globally from 8) What is a callback function in JavaScript? any part of the code. a) A function that performs asynchronous tasks. c) A function that is defined inside another b) A function that is called at the end of the function and has access to its outer function's program's execution. variables. c) A function that is passed as an argument to d) A function that takes an unlimited number of another function and is executed inside that arguments function. 16) What will be the output of: d) A function that is used for error handling. const promise1 = Promise.resolve('First') const promise2 = Promise.resolve('Second') const promise3 = Promise.reject('Third') 3. Using the DOM API, create an HTML element const promise4 = Promise.resolve('Fourth') , then fill it with all the names of the Person const runPromises = async () => { variable. const res1 = await Promise.all([promise1, promise2]) const res2 = await Promise.all([promise3, promise4]) Solution: return [res1, res2] } 1. Undefined: getPerson(2,P) is asynchronous task as runPromises() the result will be returned after 2 seconds. 0.5.then(res => console.log(res)) 2. Promise:.catch(err => console.log(err)) let getPerson=(i,x)=>{ a) [['First', 'Second'], ['Fourth']] return new Promise(resolve=>{ 1.5 b) [['First', 'Second'], ['Third', 'Fourth']] setTimeout(()=> resolve(x[i].name),2000) c) [['First', 'Second']] }) d) 'Third' }; 17) Which of these are true about selecting DOM getPerson(2,P).then(name=>console.log(name)) elements? a) You can select elements by CSS class name Async and await: b) You can select elements by id attribute value async function getdata(){ 1.0 c) You can select elements by tag name let p= await getPerson(2,P); d) All of the above console.log(p); 18) What will be the output of the following } JavaScript code? let x=[6,5,8,9,7]; getdata(); let a=x.reduce((a,c)=>c>a?a:c,7); 3. console.log(a); let ul=document.createElement('ul'); 2.0 a) 7 P.forEach(i => { b) 9 let li=document.createElement('li'); c) 5 li.textContent=i.name; d) Error ul.appendChild(li); 19) What will be the output of the following }); JavaScript code? document.body.appendChild(ul); let a=[5,3,2,9].map(i=>(j)=>i+j); let x=a.filter(i=>i(2)>5).forEach(i=>console.log(i(5))) a) 10,6,15 b) 10,14 c) 11,15 d) undefined 20) What is the main benefit of using WebAssembly? a) Faster performance than JavaScript b) Easier to learn than JavaScript c) More secure than JavaScript d) More compatible with older browsers than JavaScript Exercice (5 points): Given the following code: let Person =()=> '[{"name":"Ahmed"}, {"name":"adem"}, {"name":"Ali"}]'; let P=JSON.parse(Person()); let getPerson=(i,x)=>{setTimeout(()=>x[i].name,2000)}; console.log(getPerson(2,P)); 1. What will be the output of the code and why? 2. In order to obtain the correct result, update the above code using: a. Promise b. Async and await.