Klik⭐jika Anda menyukai proyek ini dan ikuti @SudheerJonna untuk pembaruan lainnya. Pertanyaan pengkodean tersedia. Versi PDF dan Epub tersedia di tab tindakan Show
Jelajahi sumber daya gratis terbaik untuk mempelajari JavaScript. Bangun proyek Anda sendiri & dapatkan sertifikasi gratis hanya dalam 25 hari
Pertanyaan Wawancara JavaScript. Pertanyaan dan Jawaban Wawancara JavaScript Teratas Daftar isiTidak. Questions123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
Beberapa perbedaan utama antara fungsi murni dan tidak murni adalah sebagai berikut, Fungsi murni Fungsi tidak murni Tidak memiliki efek samping Menyebabkan efek samping Selalu mengembalikan hasil yang sama Mengembalikan hasil yang berbeda pada setiap panggilan Mudah dibaca dan di-debug Sulit dibaca dan di-debug karena dipengaruhi oleh kode eksternalfunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_39
Ekspresi dalam javascript dapat diganti nilainya tanpa mempengaruhi perilaku program yang disebut transparansi referensial. Pure functions are referentially transparent function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();40 function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_39
Efek samping adalah modifikasi status melalui pemanggilan fungsi atau ekspresi. These side effects makes our function impure by default. Below are some side effects which makes function impure,
function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_42
Latihan Pengodean1. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();45
Menjawab. 4Deklarasi fungsi diangkat mirip dengan variabel apa pun. Jadi penempatan untuk deklarasi fungsi class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");_70 tidak ada bedanya 2. Apa output dari kode di bawah inifunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_46
Answer. 3Tentu saja nilai pengembalian class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");_71 adalah 1 karena operator kenaikan. Tapi pernyataan class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");_72 mendeklarasikan variabel lokal x. Whereas y declared as a global variable accidentally. Pernyataan ini setara dengan, function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_47 Since the block scoped variable x is undefined outside of the function, the type will be undefined too. Whereas the global variable class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");73 is available outside the function, the value is 0 and type is number 3. Apa output dari kode di bawah inifunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();48
Menjawab. 4Urutan pernyataan didasarkan pada mekanisme event loop. The order of statements follows the below order,
4. Apa output dari pemeriksaan kesetaraan di bawah inifunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();49
Menjawab. 1Ini karena masalah matematika float point. Karena angka floating point dikodekan dalam format biner, operasi penambahan pada angka tersebut menyebabkan kesalahan pembulatan. Hence, the comparison of floating points doesn't give expected results. You can find more details about the explanation here 0. 30000000000000004. com/ 5. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_50
Menjawab. 4Poin utama dalam cuplikan kode di atas adalah,
In other words, it is same as function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_51 Catatan. It returns 1object for MS Edge browser 6. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_52
Answer. 3This is a semicolon issue. Biasanya titik koma bersifat opsional dalam JavaScript. Jadi jika ada pernyataan (dalam hal ini, kembali) titik koma yang hilang, maka secara otomatis dimasukkan segera. Oleh karena itu, fungsi dikembalikan sebagai tidak terdefinisi Whereas if the opening curly brace is along with the return keyword then the function is going to be returned as expected function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();53 7. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();54
Answer. 3Operator class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");_77 akan menghapus properti objek tetapi tidak akan mengindeks ulang array atau mengubah panjangnya. So the number or elements or length of the array won't be changed. If you try to print myChars then you can observe that it doesn't set an undefined value, rather the property is removed from the array. The newer versions of Chrome use class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");78 instead of class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");79 to make the difference a bit clearer 8. What is the output of below code in latest Chromefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();55
Menjawab. 2The latest chrome versions display class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");80(they are filled with holes) using this empty x n notation. Whereas the older versions have undefined x n notation. Catatan. The latest version of FF displays class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");81 notation 9. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();56
Menjawab. 1ES6 menyediakan definisi metode dan singkatan properti untuk objek. So both prop2 and prop3 are treated as regular function values 10. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();57
Menjawab. 2The important point is that if the statement contains the same operators(e. g, < atau >) maka dapat dievaluasi dari kiri ke kanan. The first statement follows the below order,
Whereas the second statement follows the below order,
11. What is the output of below code in non-strict modefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();58
Menjawab. 2In non-strict mode, the regular JavaScript functions allow duplicate named parameters. Cuplikan kode di atas memiliki parameter duplikat pada parameter ke-1 dan ke-3. Nilai parameter pertama dipetakan ke argumen ketiga yang diteruskan ke fungsi. Hence, the 3rd argument overrides the first parameter Note. Dalam mode ketat, parameter duplikat akan memunculkan Kesalahan Sintaks 12. Apa output dari kode di bawah inifunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();59
Answer. 3Unlike regular functions, the arrow functions doesn't not allow duplicate parameters in either strict or non-strict mode. So you can see // Create a new instance using function prototype. var newInstance = Object.create(func.prototype) // Call the function var result = func.call(newInstance, x, y, z), // If the result is a non-null object then use it otherwise just use the new instance. console.log(result && typeof result === 'object' ? result : newInstance);44 in the console 13. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();60
Menjawab. 1Fungsi panah tidak memiliki ikatan class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");_85. Jadi setiap referensi ke variabel class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");86 mencoba untuk menyelesaikan ke pengikatan dalam lingkungan yang tertutup secara leksikal. In this case, the arguments variable is not defined outside of the arrow function. Hence, you will receive a reference error Where as the normal function provides the number of arguments passed to the function function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();61 Tapi Jika Anda masih ingin menggunakan fungsi panah maka operator istirahat pada argumen memberikan argumen yang diharapkan function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();62 14. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();63
Menjawab. 2In order to be consistent with functions like class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");87, the standard method name for trimming the whitespaces is considered as class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");88. Karena alasan kompatibilitas web, nama metode lama 'trimLeft' masih berfungsi sebagai alias untuk 'trimStart'. Hence, the prototype for 'trimLeft' is always 'trimStart' 15. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();64
Menjawab. 4-Infinity is the initial comparant because almost every other value is bigger. So when no arguments are provided, -Infinity is going to be returned. Note. Nol jumlah argumen adalah kasus yang valid 16. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_65
Menjawab. 1As per the comparison algorithm in the ECMAScript specification(ECMA-262), the above expression converted into JS as below function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();66 So it doesn't matter about number brackets([]) around the number, it is always converted to a number in the expression 17. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();67
Menjawab. 2The concatenation operator(+) is applicable for both number and string types. So if any operand is string type then both operands concatenated as strings. Whereas subtract(-) operator tries to convert the operands as number type 18. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();68
Menjawab. 1In comparison operators, the expression class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");89 converted to Number([0]. valueOf(). toString()) which is resolved to false. Whereas class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");89 just becomes a truthy value without any conversion because there is no comparison operator 19. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();69
Menjawab. 4The + operator is not meant or defined for arrays. So it converts arrays into strings and concatenates them 20. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();70
Menjawab. 1Since class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");09 object is a collection of unique values, it won't allow duplicate values in the collection. At the same time, it is case sensitive data structure 21. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();71
Menjawab. 2JavaScript follows IEEE 754 spec standards. As per this spec, NaNs are never equal for floating-point numbers 22. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();72
Menjawab. 4The class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");20 uses strict equality operator(===) internally and class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");93 evaluates to false. Since indexOf won't be able to find NaN inside an array, it returns -1 always. But you can use class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");94 method to find out the index of NaN in an array or You can use class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");95 to check if NaN is present in an array or not function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_73 23. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();74
Answer. 3When using rest parameters, trailing commas are not allowed and will throw a SyntaxError. Jika Anda menghapus tanda koma maka ini akan menampilkan jawaban pertama function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();75 25. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();76
Menjawab. 1Async functions always return a promise. But even if the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise. The above async function is equivalent to below expression, function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();77 26. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_78
Menjawab. 4The await expression returns value 10 with promise resolution and the code after each await expression can be treated as existing in a function func() {}; new func(x, y, z);71 callback. In this case, there is no return expression at the end of the function. Hence, the default return value of class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");79 is returned as the resolution of the promise. The above async function is equivalent to below expression, function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();79 27. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();80
Menjawab. 1Even though “processArray” is an async function, the anonymous function that we use for class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");98 is synchronous. If you use await inside a synchronous function then it throws a syntax error 28. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();81
Menjawab. 4The forEach method will not wait until all items are finished but it just runs the tasks and goes next. Hence, the last statement is displayed first followed by a sequence of promise resolutions But you control the array sequence using for. of loop, function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();82 29. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();83
Menjawab. 1Set has few exceptions from equality check,
30. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();84
Answer. 3Symbol follows below conventions,
Note. The symbol description is just useful for debugging purposes 31. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();85
Menjawab. 1var object = new (function () { this.name = "Sudheer"; })();00 is a just a standard function and not an object constructor(unlike other primitives new Boolean, new String and new Number). So if you try to call it with the new operator will result in a TypeError 32. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();86
Menjawab. 4The return value of var object = new (function () { this.name = "Sudheer"; })();01 or var object = new (function () { this.name = "Sudheer"; })();02 is always a truthy value (either "number" or "string"). The . operator operates on either var object = new (function () { this.name = "Sudheer"; })();01 or var object = new (function () { this.name = "Sudheer"; })();02, converting them to boolean values. Since the value of both var object = new (function () { this.name = "Sudheer"; })();05 and var object = new (function () { this.name = "Sudheer"; })();06 is false, the if condition fails, and control goes to else block To make the . operator operate on the equality expression, one needs to add parentheses function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();87 Or simply use the inequality operator function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();88 33. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();89
Menjawab. 2The symbols has below constraints,
34. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();90
Menjawab. 2Using constructors, class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");47 refers to the constructor (points to the class definition of class which is initialized) that was directly invoked by new. This also applies to the case if the constructor is in a parent class and was delegated from a child constructor 35. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();91
Menjawab. 4It throws a syntax error because the rest element should not have a trailing comma. You should always consider using a rest operator as the last element 36. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();92
Menjawab. 1The object property follows below rules,
37. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();93
Menjawab. 2If you leave out the right-hand side assignment for the destructuring object, the function will look for at least one argument to be supplied when invoked. Kalau tidak, Anda akan menerima kesalahan var object = new (function () { this.name = "Sudheer"; })();_09 seperti yang disebutkan di atas You can avoid the error with either of the below changes,
function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();94
function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();95 38. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();96
Menjawab. 1It is possible to combine Array and Object destructuring. In this case, the third element in the array props accessed first followed by name property in the object 39. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();97
Answer. 3If the function argument is set implicitly(not passing argument) or explicitly to undefined, the value of the argument is the default parameter. Whereas for other falsy values('' or null), the value of the argument is passed as a parameter Hence, the result of function calls categorized as below,
40. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();98
Menjawab. 2Since the default argument is evaluated at call time, a new object is created each time the function is called. So in this case, the new array is created and an element pushed to the default empty array 41. What is the output of below codefunction Person() {} Person.prototype.name = "Sudheer"; var object = new Person();99
Menjawab. 2Since parameters defined earlier are available to later default parameters, this code snippet doesn't throw any error 42. What is the output of below codefunction func() {}; new func(x, y, z);00
Menjawab. 1The functions and variables declared in the function body cannot be referred from default value parameter initializers. If you still try to access, it throws a run-time ReferenceError(i. e, var object = new (function () { this.name = "Sudheer"; })();10 is not defined) 43. What is the output of below codefunction func() {}; new func(x, y, z);01
Answer. 3The rest parameter is used to hold the remaining parameters of a function and it becomes an empty array if the argument is not provided 44. What is the output of below codefunction func() {}; new func(x, y, z);02
Menjawab. 2Sintaks spread hanya dapat diterapkan pada objek yang dapat diubah. By default, Objects are not iterable, but they become iterable when used in an Array, or with iterating functions such as var object = new (function () { this.name = "Sudheer"; })();11. If you still try to do it, it still throws var object = new (function () { this.name = "Sudheer"; })();12 45. What is the output of below codefunction func() {}; new func(x, y, z);03
Menjawab. 4Generators are not constructible type. Tetapi jika Anda tetap melakukannya, akan ada pesan kesalahan yang mengatakan "TypeError. myGenFunc is not a constructor" 46. What is the output of below codefunction func() {}; new func(x, y, z);04
Menjawab. 1A return statement in a generator function will make the generator finish. If a value is returned, it will be set as the value property of the object and done property to true. When a generator is finished, subsequent next() calls return an object of this form. var object = new (function () { this.name = "Sudheer"; })();_13 47. What is the output of below codefunction func() {}; new func(x, y, z);05
Menjawab. 4The generator should not be re-used once the iterator is closed. i. e, Upon exiting a loop(on completion or using break & return), the generator is closed and trying to iterate over it again does not yield any more results. Hence, the second loop doesn't print any value 48. What is the output of below codefunction func() {}; new func(x, y, z);06
Menjawab. 1If you use an invalid number(outside of 0-7 range) in the octal literal, JavaScript will throw a SyntaxError. In ES5, it treats the octal literal as a decimal number 49. What is the output of below codefunction func() {}; new func(x, y, z);07
Menjawab. 2Unlike function declarations, class declarations are not hoisted. i. e, First You need to declare your class and then access it, otherwise it will throw a ReferenceError "Uncaught ReferenceError. Square is not defined" Note. Class expressions also applies to the same hoisting restrictions of class declarations 50. What is the output of below codefunction func() {}; new func(x, y, z);08
Menjawab. 4When a regular or prototype method is called without a value for this, the methods return an initial this value if the value is not undefined. Otherwise global window object will be returned. In our case, the initial function func() {}; new func(x, y, z);47 value is undefined so both methods return window objects 51. What is the output of below codefunction func() {}; new func(x, y, z);09
Answer. 3The super keyword is used to call methods of a superclass. Unlike other languages the super invocation doesn't need to be a first statement. i. e, The statements will be executed in the same order of code 52. What is the output of below codefunction func() {}; new func(x, y, z);10
Menjawab. 2Even though we used constant variables, the content of it is an object and the object's contents (e. g properti) dapat diubah. Oleh karena itu, perubahan akan berlaku dalam kasus ini 53. What is the output of below codefunction func() {}; new func(x, y, z);_11
Menjawab. 2Emoji adalah unicode dan unicode untuk simbol senyum adalah "U+1F642". The unicode comparision of same emojies is equivalent to string comparison. Oleh karena itu, output selalu benar 54. What is the output of below code?function func() {}; new func(x, y, z);12
Menjawab. 1Operator typeof pada primitif apa pun mengembalikan nilai string. So even if you apply the chain of typeof operators on the return value, it is always string 55. What is the output of below code?function func() {}; new func(x, y, z);_13
Menjawab. 1
Hence the above code block always goes to if section 55. What is the output of below code in non strict mode?function func() {}; new func(x, y, z);14
Menjawab. 4Ini mengembalikan undefined untuk mode non-ketat dan mengembalikan Error untuk mode ketat. In non-strict mode, the wrapper object is going to be created and get the mentioned property. Tetapi objek tersebut menghilang setelah mengakses properti di baris berikutnya 56. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);15
Menjawab. 111 dan 10 dicatat ke konsol The innerFunc is a closure which captures the count variable from the outerscope. i. e, 10. But the conditional has another local variable var object = new (function () { this.name = "Sudheer"; })();15 which overwrites the ourter var object = new (function () { this.name = "Sudheer"; })();15 variable. Jadi konsol pertama. log displays value 11. Whereas the second console. log log 10 dengan menangkap variabel count dari outerscope 57. Apa output dari kode di bawah ini?
Alasan. The operator returns the value of the first falsy operand encountered when evaluating from left to right, or the value of the last operand if they are all truthy Catatan. Di bawah nilai ini dianggap nilai palsu
58. What is the output of below code ?function func() {}; new func(x, y, z);16
Answer. 3Arrays have their own implementation of var object = new (function () { this.name = "Sudheer"; })();17 method that returns a comma-separated list of elements. So the above code snippet returns true. In order to avoid conversion of array type, we should use === for comparison 59. What is the output of below code?function func() {}; new func(x, y, z);17
Menjawab. 2Hoisting will move variables and functions to be the top of scope. Even though getMessage is an arrow function the above function will considered as a varible due to it's variable declaration or assignment. Jadi variabel akan memiliki nilai yang tidak ditentukan dalam fase memori dan melontarkan kesalahan ' var object = new (function () { this.name = "Sudheer"; })();18 bukan fungsi' pada fase eksekusi kode 60. What is the output of below code?function func() {}; new func(x, y, z);18
Answer. 3Even though a promise is resolved immediately, it won't be executed immediately because its . then/catch/finally handlers or callbacks(aka task) are pushed into the queue. Whenever the JavaScript engine becomes free from the current program, it pulls a task from the queue and executes it. This is the reason why last statement is printed first before the log of promise handler Note. We call the above queue as "MicroTask Queue" 61. What is the output of below code?function func() {}; new func(x, y, z);19
Menjawab. 4When JavaScript encounters a line break without a semicolon, the JavaScript parser will automatically add a semicolon based on a set of rules called var object = new (function () { this.name = "Sudheer"; })();25 which determines whether line break as end of statement or not to insert semicolon. But it does not assume a semicolon before square brackets [. ]. So the first two lines considered as a single statement as below function func() {}; new func(x, y, z);20 Hence, there will be cannot read properties of undefined error while applying the array square bracket on log function 62. Write a function that returns a random HEX colorSolution 1 (Iterative generation)function func() {}; new func(x, y, z);_21Solusi 2 (Satu baris) function func() {}; new func(x, y, z);_22 63. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_23
Menjawab. 1Dalam JavaScript, var object = new (function () { this.name = "Sudheer"; })();_26 tidak dianggap sebagai kata kunci yang dipesan. Jadi deklarasi variabel dengan var object = new (function () { this.name = "Sudheer"; })();_26 diterima dan mencetak nilai array var object = new (function () { this.name = "Sudheer"; })();26 menggunakan for. dari lingkaran Tetapi jika Anda menggunakan kata kunci yang dipesan seperti var object = new (function () { this.name = "Sudheer"; })();29 maka akan ada kesalahan sintaks yang mengatakan var object = new (function () { this.name = "Sudheer"; })();30, function func() {}; new func(x, y, z);_24 64. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_25
Menjawab. 2Secara default, metode pengurutan mengurutkan elemen menurut abjad. Ini karena elemen dikonversi menjadi string dan string dibandingkan dalam urutan unit kode UTF-16. Karenanya, Anda akan melihat angka-angka di atas tidak diurutkan seperti yang diharapkan. In order to sort numerically just supply a comparator function which handles numeric sorts function func() {}; new func(x, y, z);_26 Catatan. Sort() metode mengubah array asli 65. Apa urutan output dari kode di bawah ini?function func() {}; new func(x, y, z);_27
Menjawab. 4Ketika mesin JavaScript mem-parsing kode di atas, dua pernyataan pertama bersifat asinkron yang akan dieksekusi kemudian dan pernyataan ketiga adalah pernyataan sinkron yang akan dipindahkan ke callstack, dieksekusi dan mencetak angka 3 di konsol. Selanjutnya, Promise adalah native di ES6 dan akan dipindahkan ke antrean Job yang memiliki prioritas lebih tinggi daripada antrean panggilan balik dalam urutan eksekusi. Akhirnya, karena setTimeout adalah bagian dari WebAPI, fungsi panggilan balik dipindahkan ke antrean panggilan balik dan dijalankan. Oleh karena itu, Anda akan melihat nomor 2 dicetak terlebih dahulu diikuti oleh 1 66. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_28
Menjawab. 4IIFE (Ekspresi Fungsi Segera Dipanggil) sama seperti ekspresi fungsi lainnya yang tidak akan diangkat. Oleh karena itu, akan ada kesalahan referensi untuk panggilan pesan. Perilaku akan sama dengan ekspresi fungsi message1 di bawah ini, function func() {}; new func(x, y, z);_29 67. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_30
Answer. 3Sebagai bagian dari pengangkatan, awalnya Mesin JavaScript atau kompiler akan menyimpan fungsi pertama di memori heap tetapi kemudian menulis ulang atau mengganti dengan konten fungsi yang didefinisikan ulang 68. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_31
Answer. 3Karena fitur hositing, variabel yang dideklarasikan dengan function func() {}; new func(x, y, z);52 akan memiliki nilai class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");79 pada fase pembuatan sehingga variabel luar var object = new (function () { this.name = "Sudheer"; })();33 akan mendapatkan nilai class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");79 yang sama. Tetapi setelah beberapa baris kode, mesin JavaScript menemukan panggilan fungsi baru ( var object = new (function () { this.name = "Sudheer"; })();35) untuk memperbarui kota saat ini dengan deklarasi ulang function func() {}; new func(x, y, z);52. Karena setiap pemanggilan fungsi akan membuat konteks eksekusi baru, variabel yang sama akan memiliki nilai ________7______79 sebelum deklarasi dan nilai baru( var object = new (function () { this.name = "Sudheer"; })();38) setelah deklarasi. Oleh karena itu, nilai class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");79 print terlebih dahulu diikuti dengan nilai baru var object = new (function () { this.name = "Sudheer"; })();38 pada tahap eksekusi 69. Apa output dari kode di bawah ini secara berurutan?function func() {}; new func(x, y, z);_32
Menjawab. 1Setiap konteks (global atau fungsional) memiliki lingkungan variabelnya sendiri dan tumpukan panggilan variabel dalam urutan LIFO. Jadi Anda dapat melihat nilai variabel pesan dari fungsi kedua, pertama dalam urutan diikuti oleh nilai variabel pesan konteks global di bagian akhir 70. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_33
Menjawab. 1Pemanggilan fungsi var object = new (function () { this.name = "Sudheer"; })();41 tidak akan menjadi bagian dari rantai lingkup dan memiliki konteks eksekusi sendiri dengan lingkungan variabel terlampir. saya. e, Itu tidak akan diakses dari konteks global. Oleh karena itu, akan terjadi kesalahan saat menjalankan fungsi sebagai var object = new (function () { this.name = "Sudheer"; })();42 71. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_34
Menjawab. 4function func() {}; new func(x, y, z);47 kata kunci adalah ruang lingkup dinamis tetapi tidak ruang lingkup leksikal. Dengan kata lain, tidak masalah di mana function func() {}; new func(x, y, z);47 telah ditulis tetapi bagaimana itu telah dipanggil sangat penting. Dalam cuplikan kode di atas, objek var object = new (function () { this.name = "Sudheer"; })();_45 memanggil fungsi var object = new (function () { this.name = "Sudheer"; })();46 sehingga kata kunci function func() {}; new func(x, y, z);47 merujuk ke objek var object = new (function () { this.name = "Sudheer"; })();45 tetapi var object = new (function () { this.name = "Sudheer"; })();49 telah dipanggil oleh fungsi var object = new (function () { this.name = "Sudheer"; })();46 dan function func() {}; new func(x, y, z);47 akan memiliki objek default var object = new (function () { this.name = "Sudheer"; })();_52 Pit fall di atas diperbaiki dengan tiga cara,
function func() {}; new func(x, y, z);_35 Dua solusi berikutnya telah digunakan sebelum ES6 diperkenalkan
function func() {}; new func(x, y, z);_36
function func() {}; new func(x, y, z);_37 72. What is the output of below code?function func() {}; new func(x, y, z);_38
Answer. 3Dalam JavaScript, primitif tidak dapat diubah i. e. tidak ada cara untuk mengubah nilai primitif setelah dibuat. Jadi ketika Anda mencoba memperbarui karakter pertama string, tidak ada perubahan nilai string dan mencetak nilai awal yang sama var object = new (function () { this.name = "Sudheer"; })();65. Sedangkan pada contoh selanjutnya, nilai gabungan ditugaskan kembali ke variabel yang sama yang akan menghasilkan pembuatan blok memori baru dengan referensi menunjuk ke nilai var object = new (function () { this.name = "Sudheer"; })();66 dan nilai blok memori lama ( var object = new (function () { this.name = "Sudheer"; })();67) akan menjadi sampah yang dikumpulkan 73. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_39
Menjawab. 2Dalam JavaScript, variabel seperti objek, array, dan fungsi berada di bawah referensi. Saat Anda mencoba membandingkan dua objek dengan konten yang sama, itu akan membandingkan alamat memori atau referensi dari variabel tersebut. Variabel-variabel ini selalu membuat blok memori terpisah sehingga perbandingannya selalu akan mengembalikan nilai palsu 74. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_40
Answer. 3Variabel var object = new (function () { this.name = "Sudheer"; })();_68 masih diperlakukan sebagai penutupan (karena telah digunakan dalam fungsi dalam) meskipun telah dideklarasikan setelah fungsi setTimeout. Fungsi dengan fungsi setTimeout akan dikirim ke WebAPI dan deklarasi variabel dieksekusi dalam 5 detik dengan nilai yang ditetapkan. Karenanya, teks yang dideklarasikan untuk variabel akan ditampilkan 75. What is the output of below code?function func() {}; new func(x, y, z);_41
Menjawab. 1Meskipun kedua variabel class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");61 dan // Create a new instance using function prototype. var newInstance = Object.create(func.prototype) // Call the function var result = func.call(newInstance, x, y, z), // If the result is a non-null object then use it otherwise just use the new instance. console.log(result && typeof result === 'object' ? result : newInstance);17 merujuk nilai angka, deklarasi pertama didasarkan pada fungsi konstruktor dan tipe variabel akan menjadi tipe var object = new (function () { this.name = "Sudheer"; })();71. Sedangkan deklarasi kedua adalah penugasan primitif dengan angka dan tipenya adalah tipe var object = new (function () { this.name = "Sudheer"; })();72. Oleh karena itu, operator kesetaraan var object = new (function () { this.name = "Sudheer"; })();_73 akan menampilkan nilai class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");07 76. Apa jenis fungsi di bawah ini?function func() {}; new func(x, y, z);_42
Menjawab. 2Meskipun fungsi di atas mengembalikan hasil yang sama untuk argumen (input) yang sama yang diteruskan dalam fungsi, pernyataan var object = new (function () { this.name = "Sudheer"; })();75 menyebabkan fungsi memiliki efek samping karena memengaruhi status kode eksternal. i. e, status objek var object = new (function () { this.name = "Sudheer"; })();_76 dan bergantung padanya untuk melakukan pekerjaan. Oleh karena itu, fungsi di atas dianggap sebagai fungsi tidak murni 77. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_43
Menjawab. 2The above promises settled at the same time but one of them resolved and other one rejected. Ketika Anda menggunakan metode var object = new (function () { this.name = "Sudheer"; })();_77 pada janji-janji ini, hasilnya akan disingkat dengan melemparkan kesalahan karena penolakan pada janji kedua. Tetapi Jika Anda menggunakan metode var object = new (function () { this.name = "Sudheer"; })();_78 maka hasil dari kedua janji tersebut akan dikembalikan terlepas dari status janji yang diselesaikan atau ditolak tanpa menimbulkan kesalahan apa pun function func() {}; new func(x, y, z);_44 78. Apa output dari kode di bawah ini?function func() {}; new func(x, y, z);_45
Answer. 3Jika Anda memasukkan metode // Create a new instance using function prototype. var newInstance = Object.create(func.prototype) // Call the function var result = func.call(newInstance, x, y, z), // If the result is a non-null object then use it otherwise just use the new instance. console.log(result && typeof result === 'object' ? result : newInstance);75 dan var object = new (function () { this.name = "Sudheer"; })();80 di dalam klausa try dan pengecualian dilemparkan, klausa catch tidak akan menangkap salah satu dari mereka. This is because the try. pernyataan catch bekerja secara sinkron, dan fungsi dalam kode di atas dijalankan secara asinkron setelah jangka waktu tertentu. Karenanya, Anda akan melihat pengecualian runtime tanpa mengetahui kesalahannya. Untuk mengatasi masalah ini, Anda harus mencoba. catch block inside the function as below, function func() {}; new func(x, y, z);_46 Anda dapat menggunakan fungsi var object = new (function () { this.name = "Sudheer"; })();_81 dalam promise untuk menghindari masalah ini dengan kode asinkron DisclaimerThe questions provided in this repository are the summary of frequently asked questions across numerous companies. Kami tidak dapat menjamin bahwa pertanyaan-pertanyaan ini akan benar-benar ditanyakan selama proses wawancara Anda, Anda juga tidak boleh fokus untuk menghafal semuanya. Tujuan utamanya adalah agar Anda memahami apa yang mungkin ditanyakan oleh beberapa perusahaan — jangan berkecil hati jika Anda tidak mengetahui jawaban untuk semuanya — tidak apa-apa Is it OK to use JavaScript for coding interview?Jawabannya adalah ya. Sebagian besar perusahaan mengizinkan Anda membuat kode dalam bahasa apa pun yang Anda inginkan - satu-satunya pengecualian yang saya tahu adalah Google, di mana mereka hanya mengizinkan kandidat untuk memilih dari Java, C++, JavaScript .
How to prepare for JavaScript coding interview?How to prepare for JavaScript interviews . Langkah 1. Ketahui apa yang perlu Anda pelajari. Anda sudah tahu bahasa pemrograman apa yang akan Anda gunakan, jadi sekarang Anda perlu meneliti aspek apa dari bahasa itu yang akan diuji. . Langkah 2. Membuat rencana. . Langkah 3. Jangan lupakan wawancara perilaku Bisakah saya menggunakan JavaScript untuk wawancara Google?Bisakah saya menggunakan JavaScript untuk wawancara? . Note, however, that if interviewers want to check your skill in a particular language, that changes. Jika solusinya jauh lebih baik dalam bahasa OOP yang berbeda, Anda harus memiliki alasan yang kuat untuk tidak memilihnya. Yes, as long as that's the language you know best, you can usually use it. Note, however, that if interviewers want to check your skill in a particular language, that changes. If the solution is much better in a different OOP language, you should have a good reason not to choose it.
How to practice JavaScript interview questions?Pertanyaan dan Jawaban Wawancara JavaScript Tingkat Pemula untuk Mahasiswa Baru . Q1. Apa perbedaan antara Java & JavaScript? Q2. Apa itu JavaScript? Q3. Apa tipe data yang didukung oleh JavaScript? Q4. Apa saja fitur JavaScript? Q5. Apakah JavaScript adalah bahasa yang peka terhadap huruf besar-kecil? Q6. . Q7. . |