Menggunakan javascript untuk coding wawancara

Klik⭐jika Anda menyukai proyek ini dan ikuti @SudheerJonna untuk pembaruan lainnya. Pertanyaan pengkodean tersedia. Versi PDF dan Epub tersedia di tab tindakan

Jelajahi sumber daya gratis terbaik untuk mempelajari JavaScript. Bangun proyek Anda sendiri & dapatkan sertifikasi gratis hanya dalam 25 hari

  1. Ikuti kursus Proyek JavaScript ini untuk beralih dari pemula JS hingga membangun proyek Anda sendiri dengan percaya diri
  2. Ikuti bootcamp wawancara coding ini jika Anda serius ingin dipekerjakan dan tidak memiliki gelar CS
  3. Ikuti Kursus JavaScript Tingkat Lanjut ini untuk mempelajari konsep JS tingkat lanjut dan menjadi pengembang JS teratas

Pertanyaan Wawancara JavaScript. Pertanyaan dan Jawaban Wawancara JavaScript Teratas

Daftar isi

Tidak. Questions123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. What are the possible ways to create objects in JavaScript

    There are many ways to create objects in javascript as below

    1. Object constructor

      The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended

      var object = new Object();

    2. Object's create method

      The create method of Object creates a new object by passing the prototype object as a parameter

      var object = Object.create(null);

    3. Object literal syntax

      The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces

      var object = { name: "Sudheer", age: 34 }; Object literal property values can be of any data type, including array, function, and nested object.

      Note. This is an easiest way to create an object

    4. Function constructor

      Create any function and apply the new operator to create object instances,

      function Person(name) { this.name = name; this.age = 21; } var object = new Person("Sudheer");

    5. Function constructor with prototype

      This is similar to function constructor but it uses prototype for their properties and methods,

      function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_

      Ini setara dengan instance yang dibuat dengan metode pembuatan objek dengan prototipe fungsi dan kemudian memanggil fungsi itu dengan instance dan parameter sebagai argumen

      function func() {}; new func(x, y, z);

      (ATAU)

      // 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);_

    6. Sintaks Kelas ES6

      ES6 memperkenalkan fitur kelas untuk membuat objek

      class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");

    7. Pola tunggal

      A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don't accidentally create multiple instances

      var object = new (function () { this.name = "Sudheer"; })();

  2. What is a prototype chain

    Prototype chaining is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language

    The prototype on object instance is available through Object. getPrototypeOf(object) or __proto__ property whereas prototype on constructors function is available through Object. prototype

    function func() {}; new func(x, y, z);81 element. i. e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression. For example, the below link notify the message without reloading the page

    var object = new (function () { this.name = "Sudheer"; })();5

  3. Is JavaScript a compiled or interpreted language

    JavaScript is an interpreted language, not a compiled language. Penerjemah di browser membaca kode JavaScript, menafsirkan setiap baris, dan menjalankannya. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run

  4. Is JavaScript a case-sensitive language

    Yes, JavaScript is a case sensitive language. The language keywords, variables, function & object names, and any other identifiers must always be typed with a consistent capitalization of letters

  5. Is there any relation between Java and JavaScript

    No, they are entirely two different programming languages and have nothing to do with each other. But both of them are Object Oriented Programming languages and like many other languages, they follow similar syntax for basic features(if, else, for, switch, break, continue etc)

  6. What are events

    Events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can function func() {}; new func(x, y, z);82 on these events. Some of the examples of HTML events are,

    1. Web page has finished loading
    2. Input field was changed
    3. Button was clicked

    Let's describe the behavior of click event for button element,

    var object = new (function () { this.name = "Sudheer"; })();6

  7. Who created javascript

    JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name function func() {}; new func(x, y, z);83, but later the language was officially called function func() {}; new func(x, y, z);84 when it first shipped in beta releases of Netscape

  8. What is the use of preventDefault method

    The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases

    var object = new (function () { this.name = "Sudheer"; })();7

    Note. Remember that not all events are cancelable

  9. What is the use of stopPropagation method

    The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)

    var object = new (function () { this.name = "Sudheer"; })();8

  10. What are the steps involved in return false usage

    The return false statement in event handlers performs the below steps,

    1. First it stops the browser's default action or behaviour
    2. It prevents the event from propagating the DOM
    3. Stops callback execution and returns immediately when called

  11. What is BOM

    The Browser Object Model (BOM) allows JavaScript to "talk to" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers

  12. What is the use of setTimeout

    The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,

    var object = new (function () { this.name = "Sudheer"; })();9

  13. What is the use of setInterval

    The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?0

  14. Why is JavaScript treated as Single threaded

    JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs

  15. What is an event delegation

    Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it

    For example, if you wanted to detect field changes in inside a specific form, you can use event delegation technique,

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_1

  16. What is ECMAScript

    ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. Edisi pertama ECMAScript dirilis pada tahun 1997

  17. Apa itu JSON

    JSON (JavaScript Object Notation) adalah format ringan yang digunakan untuk pertukaran data. Ini didasarkan pada subset bahasa JavaScript dengan cara objek dibangun dalam JavaScript

  18. Apa aturan sintaks JSON

    Di bawah ini adalah daftar aturan sintaks JSON

    1. Data dalam pasangan nama/nilai
    2. Data dipisahkan dengan koma
    3. Kurung kurawal menahan objek
    4. Kurung persegi menahan array

  19. Apa tujuan JSON merangkai

    Saat mengirim data ke server web, data harus dalam format string. Anda dapat mencapainya dengan mengonversi objek JSON menjadi string menggunakan metode stringify()

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_2

  20. Bagaimana Anda mengurai string JSON

    Saat menerima data dari server web, data selalu dalam format string. Tetapi Anda dapat mengonversi nilai string ini menjadi objek javascript menggunakan metode parse()

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_3

  21. Mengapa Anda membutuhkan JSON

    Saat bertukar data antara browser dan server, data hanya dapat berupa teks. Karena JSON hanya berupa teks, JSON dapat dengan mudah dikirim ke dan dari server, dan digunakan sebagai format data oleh bahasa pemrograman apa pun

  22. Apa itu PWA

    Aplikasi web progresif (PWA) adalah jenis aplikasi seluler yang dikirimkan melalui web, dibangun menggunakan teknologi web umum termasuk HTML, CSS, dan JavaScript. PWA ini disebarkan ke server, dapat diakses melalui URL, dan diindeks oleh mesin pencari

  23. Apa tujuan dari metode clearTimeout

    Fungsi clearTimeout() digunakan dalam javascript untuk menghapus batas waktu yang telah ditetapkan oleh fungsi setTimeout() sebelumnya. saya. e, Nilai pengembalian fungsi setTimeout() disimpan dalam variabel dan diteruskan ke fungsi clearTimeout() untuk menghapus timer

    Misalnya, metode setTimeout di bawah ini digunakan untuk menampilkan pesan setelah 3 detik. Batas waktu ini dapat dihapus dengan metode clearTimeout()

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_4

  24. Apa tujuan dari metode clearInterval

    Fungsi clearInterval() digunakan dalam javascript untuk menghapus interval yang telah diatur oleh fungsi setInterval(). saya. e, Nilai pengembalian yang dikembalikan oleh fungsi setInterval() disimpan dalam variabel dan diteruskan ke fungsi clearInterval() untuk menghapus interval

    Misalnya, metode setInterval di bawah ini digunakan untuk menampilkan pesan setiap 3 detik. Interval ini dapat dihapus dengan metode clearInterval()

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_5

  25. Bagaimana Anda mengarahkan ulang halaman baru dalam javascript

    Dalam javascript vanilla, Anda dapat mengarahkan ulang ke halaman baru menggunakan properti function func() {}; new func(x, y, z);85 dari objek jendela. Sintaksnya adalah sebagai berikut,

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_6

  26. Bagaimana Anda memeriksa apakah string berisi substring

    Ada 3 cara yang mungkin untuk memeriksa apakah string berisi substring atau tidak,

    1. Menggunakan termasuk. ES6 menyediakan metode function func() {}; new func(x, y, z);86 untuk menguji sebuah string berisi substring

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_7

    1. Menggunakan indexOf. Di lingkungan ES5 atau yang lebih lama, Anda dapat menggunakan function func() {}; new func(x, y, z);87 yang mengembalikan indeks substring. Jika nilai indeks tidak sama dengan -1 berarti substring tersebut ada di string utama

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_8

    1. Menggunakan RegEx. Solusi lanjutan menggunakan metode uji ekspresi reguler (function func() {}; new func(x, y, z);88), yang memungkinkan pengujian terhadap ekspresi reguler

    var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?_9

  27. Bagaimana Anda memvalidasi email dalam javascript

    Anda dapat memvalidasi email dalam javascript menggunakan ekspresi reguler. Disarankan untuk melakukan validasi di sisi server daripada di sisi klien. Karena javascript dapat dinonaktifkan di sisi klien

    var object = Object.create(null);_00

    Ekspresi reguler di atas menerima karakter unicode

  28. Bagaimana Anda mendapatkan url saat ini dengan javascript

    Anda dapat menggunakan ekspresi function func() {}; new func(x, y, z);_89 untuk mendapatkan jalur url saat ini dan Anda juga dapat menggunakan ekspresi yang sama untuk memperbarui URL. Anda juga dapat menggunakan function func() {}; new func(x, y, z);_90 untuk tujuan hanya-baca tetapi solusi ini memiliki masalah di FF

    var object = Object.create(null);01

  29. What are the various url properties of location object

    The below function func() {}; new func(x, y, z);91 object properties can be used to access URL components of the page,

    1. href - The entire URL
    2. protocol - The protocol of the URL
    3. host - The hostname and port of the URL
    4. hostname - The hostname of the URL
    5. port - The port number in the URL
    6. pathname - The path name of the URL
    7. search - The query portion of the URL
    8. hash - The anchor portion of the URL

  30. How do get query string values in javascript

    You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,

    var object = Object.create(null);02

  31. How do you check if a key exists in an object

    You can check whether a key exists in an object or not using three approaches,

    1. Using in operator. You can use the in operator whether a key exists in an object or not

    var object = Object.create(null);03

    and If you want to check if a key doesn't exist, remember to use parenthesis,

    var object = Object.create(null);04

    1. Using hasOwnProperty method. You can use function func() {}; new func(x, y, z);92 to particularly test for properties of the object instance (and not inherited properties)

    var object = Object.create(null);05

    1. Using undefined comparison. If you access a non-existing property from an object, the result is undefined. Let’s compare the properties against undefined to determine the existence of the property

    var object = Object.create(null);06

  32. How do you loop through or enumerate javascript object

    You can use the function func() {}; new func(x, y, z);93 loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using function func() {}; new func(x, y, z);92 method

    var object = Object.create(null);07

  33. How do you test for an empty object

    There are different solutions based on ECMAScript versions

    1. Using Object entries(ECMA 7+). You can use object entries length along with constructor type

    var object = Object.create(null);08

    1. Using Object keys(ECMA 5+). You can use object keys length along with constructor type

    var object = Object.create(null);09

    1. Using for-in with hasOwnProperty(Pre-ECMA 5). You can use a for-in loop along with hasOwnProperty

    var object = Object.create(null);10

  34. What is an arguments object

    The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,

    var object = Object.create(null);11

    Note. You can't apply array methods on arguments object. Tetapi Anda dapat mengubahnya menjadi array biasa seperti di bawah ini

    var object = Object.create(null);12

  35. How do you make first letter of the string in an uppercase

    You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase

    var object = Object.create(null);13

  36. Apa pro dan kontra dari for loop

    for-loop adalah sintaks iterasi yang umum digunakan dalam javascript. It has both pros and cons

    Pros

    1. Bekerja di setiap lingkungan
    2. You can use break and continue flow control statements

    Cons

    1. Too verbose
    2. Imperative
    3. You might face one-by-off errors

  37. How do you display the current date in javascript

    You can use function func() {}; new func(x, y, z);95 to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy

    var object = Object.create(null);14

  38. How do you compare two date objects

    You need to use date. getTime() method to compare date values instead of comparison operators (==, . =, ===, and . == operators)

    var object = Object.create(null);15

  39. How do you check if a string starts with another string

    You can use ECMAScript 6's function func() {}; new func(x, y, z);96 method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,

    var object = Object.create(null);16

  40. How do you trim a string in javascript

    JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string

    var object = Object.create(null);17

    If your browser( (Greater than),> = (Greater than or Equal to),< (Less than),) maka dapat dievaluasi dari kiri ke kanan. The first statement follows the below order,

    1. console. log(1 < 2 < 3);
    2. console. log(benar < 3);
    3. console. log(1 < 3); // True converted as // 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);03 during comparison
    4. BENAR

    Whereas the second statement follows the below order,

    1. console. log(3 > 2 > 1);
    2. console. log(true > 1);
    3. console. log(1 > 1); // False converted as class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");83 during comparison
    4. PALSU

    11. What is the output of below code in non-strict mode

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();58

    • 1. 1, 2, 3
    • 2. 3, 2, 3
    • 3. Kesalahan sintaks. Duplicate parameter name not allowed in this context
    • 4. 1, 2, 1
    AnswerMenjawab. 2

    In 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 ini

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();59

    • 1. 1, 2, 3
    • 2. 3, 2, 3
    • 3. Kesalahan sintaks. Duplicate parameter name not allowed in this context
    • 4. 1, 2, 1
    AnswerAnswer. 3

    Unlike 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();60

    • 1. ReferenceError. arguments is not defined
    • 2. 3
    • 3. undefined
    • 4. batal
    AnswerMenjawab. 1

    Fungsi 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();63

    • 1. Benar salah
    • 2. False, True
    AnswerMenjawab. 2

    In 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();64

    • 1. undefined
    • 2. Infinity
    • 3. 0
    • 4. -Infinity
    AnswerMenjawab. 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_65

    • 1. True, True
    • 2. True, False
    • 3. False, False
    • 4. False, True
    AnswerMenjawab. 1

    As 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();67

    • 1. 20, 0
    • 2. 1010, 0
    • 3. 1010, 10-10
    • 4. NaN, NaN
    AnswerMenjawab. 2

    The 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();68

    • 1. True, I'm True
    • 2. True, I'm False
    • 3. False, I'm True
    • 4. False, I'm False
    AnswerMenjawab. 1

    In 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();69

    • 1. [1,2,3,4]
    • 2. [1,2][3,4]
    • 3. SyntaxError
    • 4. 1,23,4
    AnswerMenjawab. 4

    The + operator is not meant or defined for arrays. So it converts arrays into strings and concatenates them

    20. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();70

    • 1. {1, 2, 3, 4}, {"F", "i", "r", "e", "f", "o", "x"}
    • 2. {1, 2, 3, 4}, {"F", "i", "r", "e", "o", "x"}
    • 3. [1, 2, 3, 4], ["F", "i", "r", "e", "o", "x"]
    • 4. {1, 1, 2, 3, 4}, {"F", "i", "r", "e", "f", "o", "x"}
    AnswerMenjawab. 1

    Since 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();71

    • 1. BENAR
    • 2. False
    AnswerMenjawab. 2

    JavaScript follows IEEE 754 spec standards. As per this spec, NaNs are never equal for floating-point numbers

    22. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();72

    • 1. 4
    • 2. NaN
    • 3. SyntaxError
    • 4. -1
    AnswerMenjawab. 4

    The 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();74

    • 1. 1, [2, 3, 4, 5]
    • 2. 1, {2, 3, 4, 5}
    • 3. SyntaxError
    • 4. 1, [2, 3, 4]
    AnswerAnswer. 3

    When 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();76

    • 1: Promise {: 10}
    • 2. 10
    • 3. SyntaxError
    • 4: Promise {: 10}
    AnswerMenjawab. 1

    Async 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();_78

    • 1: Promise {: 10}
    • 2. 10
    • 3. SyntaxError
    • 4: Promise {: undefined}
    AnswerMenjawab. 4

    The 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();80

    • 1. SyntaxError
    • 2. 1, 2, 3, 4
    • 3. 4, 4, 4, 4
    • 4. 4, 3, 2, 1
    AnswerMenjawab. 1

    Even 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();81

    • 1. 1 2 3 5 and Process completed
    • 2. 5 5 5 5 and Process completed
    • 3. Process completed. and 5 5 5 5
    • 4. Process completed. and 1 2 3 5
    AnswerMenjawab. 4

    The 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();83

    • 1. Set(4) {"+0", "-0", NaN, undefined}
    • 2. Set(3) {"+0", NaN, undefined}
    • 3. Set(5) {"+0", "-0", NaN, undefined, NaN}
    • 4. Set(4) {"+0", NaN, tidak terdefinisi, NaN}
    AnswerMenjawab. 1

    Set has few exceptions from equality check,

    1. Semua nilai NaN sama
    2. Both +0 and -0 considered as different values

    30. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();84

    • 1. betul betul
    • 2. true, false
    • 3. false, true
    • 4. false, false
    AnswerAnswer. 3

    Symbol follows below conventions,

    1. Every symbol value returned from Symbol() is unique irrespective of the optional string
    2. class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");99 fungsi membuat simbol dalam daftar registri simbol global. But it doesn't necessarily create a new symbol on every call, it checks first if a symbol with the given key is already present in the registry and returns the symbol if it is found. Otherwise a new symbol created in the registry

    Note. The symbol description is just useful for debugging purposes

    31. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();85

    • 1. SyntaxError
    • 2. one
    • 3. Symbol('one')
    • 4. Symbol
    AnswerMenjawab. 1

    var 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();86

    • 1. SyntaxError
    • 2. Ini bukan string. , Ini bukan angka
    • 3. It is not a string. , It is a number
    • 4. It is a string. , It is a number
    AnswerMenjawab. 4

    The 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();89

    • 1. {"myArray". ['satu', tidak terdefinisi, {}, Simbol]}, {}
    • 2. {"myArray". ['one', null,null,null]}, {}
    • 3. {"myArray". ['one', null,null,null]}, "{ [Symbol. for('one')]. 'one' }, [Symbol. for('one')]"
    • 4. {"myArray". ['one', undefined, function(){}, Symbol('')]}, {}
    AnswerMenjawab. 2

    The symbols has below constraints,

    1. The undefined, Functions, and Symbols are not valid JSON values. So those values are either omitted (in an object) or changed to null (in an array). Hence, it returns null values for the value array
    2. All Symbol-keyed properties will be completely ignored. Hence it returns an empty object({})

    34. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();90

    • 1. A A
    • 2. A, B
    AnswerMenjawab. 2

    Using 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();91

    • 1. 1, [2, 3], 4
    • 2. 1, [2, 3, 4], undefined
    • 3. 1, [2], 3
    • 4. Kesalahan sintaks
    AnswerMenjawab. 4

    It 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();92

    • 1. 30, 20
    • 2. 10, 20
    • 3. 10, tidak ditentukan
    • 4. 30, undefined
    AnswerMenjawab. 1

    The object property follows below rules,

    1. The object properties can be retrieved and assigned to a variable with a different name
    2. The property assigned a default value when the retrieved value is class Person { constructor(name) { this.name = name; } } var object = new Person("Sudheer");79

    37. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();93

    • 1. 200
    • 2. Error
    • 3. undefined
    • 4. 0
    AnswerMenjawab. 2

    If 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,

    1. Pass at least an empty object

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();94

    1. Assign default empty object

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();95

    38. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();96

    • 1. Tom
    • 2. Error
    • 3. undefined
    • 4. John
    AnswerMenjawab. 1

    It 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();97

    • 1. number, undefined, string, object
    • 2. tidak terdefinisi, tidak terdefinisi, string, objek
    • 3. number, number, string, object
    • 4. number, number, number, number
    AnswerAnswer. 3

    If 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,

    1. The first two function calls logs number type since the type of default value is number
    2. The type of '' and null values are string and object type respectively

    40. What is the output of below code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();98

    • 1. ['Orange'], ['Orange', 'Apple']
    • 2. ['Orange'], ['Apple']
    AnswerMenjawab. 2

    Since 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 code

    function Person() {} Person.prototype.name = "Sudheer"; var object = new Person();99

    • 1. SyntaxError
    • 2. ['Hello', 'John', 'Hello John'], ['Hello', 'John', 'Good morning. ']
    AnswerMenjawab. 2

    Since parameters defined earlier are available to later default parameters, this code snippet doesn't throw any error

    42. What is the output of below code

    function func() {}; new func(x, y, z);00

    • 1. ReferenceError
    • 2. Batin
    AnswerMenjawab. 1

    The 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 code

    function func() {}; new func(x, y, z);01

    • 1. [3, 4, 5], undefined
    • 2. SyntaxError
    • 3. [3, 4, 5], []
    • 4. [3, 4, 5], [undefined]
    AnswerAnswer. 3

    The 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 code

    function func() {}; new func(x, y, z);02

    • 1. ['key', 'value']
    • 2. TypeError
    • 3. []
    • 4. ['key']
    AnswerMenjawab. 2

    Sintaks 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 code

    function func() {}; new func(x, y, z);03

    • 1. 1
    • 2. undefined
    • 3. SyntaxError
    • 4. TypeError
    AnswerMenjawab. 4

    Generators 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 code

    function func() {}; new func(x, y, z);04

    • 1. { value. 1, done. false }, { value. 2, done. true }, { value. undefined, done. true }
    • 2. { value. 1, selesai. false }, { value. 2, done. false }, { value. undefined, done. true }
    • 3. { value. 1, done. false }, { value. 2, done. true }, { value. 3, done. true }
    • 4. { value. 1, done. false }, { value. 2, done. false }, { value. 3, done. true }
    AnswerMenjawab. 1

    A 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 code

    function func() {}; new func(x, y, z);05

    • 1. 1,2,3 and 1,2,3
    • 2. 1,2,3 and 4,5,6
    • 3. 1 and 1
    • 4. 1
    AnswerMenjawab. 4

    The 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 code

    function func() {}; new func(x, y, z);06

    • 1. SyntaxError
    • 2. 38
    AnswerMenjawab. 1

    If 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 code

    function func() {}; new func(x, y, z);07

    • 1. 100
    • 2. ReferensiKesalahan
    AnswerMenjawab. 2

    Unlike 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 code

    function func() {}; new func(x, y, z);08

    • 1. undefined, undefined
    • 2. Person, Person
    • 3. SyntaxError
    • 4. Window, Window
    AnswerMenjawab. 4

    When 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 code

    function func() {}; new func(x, y, z);09

    • 1. SyntaxError
    • 2. BMW vehicle started, BMW car started
    • 3. BMW car started, BMW vehicle started
    • 4. BMW car started, BMW car started
    AnswerAnswer. 3

    The 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 code

    function func() {}; new func(x, y, z);10

    • 1. 30
    • 2. 25
    • 3. Uncaught TypeError
    • 4. Kesalahan sintaks
    AnswerMenjawab. 2

    Even 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 code

    function func() {}; new func(x, y, z);_11

    • 1. false
    • 2. BENAR
    AnswerMenjawab. 2

    Emoji 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

    • 1. string
    • 2. boolean
    • 3. NaN
    • 4. nomor
    AnswerMenjawab. 1

    Operator 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

    • 1. If
    • 2. Else
    • 3. NaN
    • 4. Kesalahan sintaks
    AnswerMenjawab. 1
    1. Jenis operator pada Nomor baru selalu mengembalikan objek. saya. e, typeof new Number(0) --> object
    2. Objek selalu benar dalam blok if

    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

    • 1. ""
    • 2. Error
    • 3. John
    • 4. Undefined
    AnswerMenjawab. 4

    Ini 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

    • 1. 11, 10
    • 2. 11, 11
    • 3. 10, 11
    • 4. 10, 10
    AnswerMenjawab. 1

    11 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?

    • 1. console. log(true && 'hi');
    • 2. menghibur. log(true && 'hi' && 1);
    • 3. console. log(true && '' && 0);
    Answer
    • 1. hai
    • 2. 1
    • 3. ''

    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

    • 1. 0
    • 2. ''
    • 3. batal
    • 4. undefined
    • 5. NAN

    58. What is the output of below code ?

    function func() {}; new func(x, y, z);16

    • 1. false
    • 2. Error
    • 3. true
    AnswerAnswer. 3

    Arrays 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

    • 1. Good morning
    • 2. getMessage is not a function
    • 3. getMessage is not defined
    • 4. Undefined
    AnswerMenjawab. 2

    Hoisting 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

    • 1. program finished
    • 2. Cannot predict the order
    • 3. program finished, promise finished
    • 4. promise finished, program finished
    AnswerAnswer. 3

    Even 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

    • 1. var object = new (function () { this.name = "Sudheer"; })();19, then print var object = new (function () { this.name = "Sudheer"; })();20 in a new line, and finally print var object = new (function () { this.name = "Sudheer"; })();21 as next line
    • 2. var object = new (function () { this.name = "Sudheer"; })();19, then print var object = new (function () { this.name = "Sudheer"; })();20 in a first line, and print var object = new (function () { this.name = "Sudheer"; })();21 as next line
    • 3. Missing semi-colon error
    • 4. Cannot read properties of undefined
    AnswerMenjawab. 4

    When 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 color

    Solution 1 (Iterative generation)

    function func() {}; new func(x, y, z);_21

    Solusi 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

    • 1. of
    • 2. Kesalahan sintaks. Token tak terduga dari
    • 3. Kesalahan sintaks. Pengenal 'dari' telah dideklarasikan
    • 4. ReferensiKesalahan. dari tidak didefinisikan
    AnswerMenjawab. 1

    Dalam 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

    • 1. [11, 18, 23, 25, 31, 33, 200]
    • 2. [11, 18, 200, 23, 25, 31, 33]
    • 3. [11, 25, 31, 23, 33, 18, 200]
    • 4. Tidak dapat mengurutkan angka
    AnswerMenjawab. 2

    Secara 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

    • 1. 1, 2, 3
    • 2. 1, 3, 2
    • 3. 3, 1, 2
    • 4. 3, 2, 1
    AnswerMenjawab. 4

    Ketika 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

    • 1. Yohanes, Halo Yohanes. Selamat datang
    • 2. undefined, Halo John, Selamat datang
    • 3. Kesalahan referensi. name is not defined, Reference error. pesan tidak ditentukan
    • 4. tidak terdefinisi, kesalahan Referensi. pesan tidak ditentukan
    AnswerMenjawab. 4

    IIFE (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

    • 1. Kesalahan referensi. pesan tidak ditentukan
    • 2. Halo
    • 3. Selamat tinggal
    • 4. Mengkompilasi kesalahan waktu
    AnswerAnswer. 3

    Sebagai 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

    • 1. New York, Singapura
    • 2. NewYork, NewYork
    • 3. tidak ditentukan, Singapura
    • 4. Singapura, Singapura
    AnswerAnswer. 3

    Karena 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

    • 1. tidak terdefinisi, pertama, default
    • 2. bawaan, bawaan, bawaan
    • 3. pertama, pertama, bawaan
    • 4. tidak terdefinisi, tidak terdefinisi, tidak terdefinisi
    AnswerMenjawab. 1

    Setiap 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

    • 1. functionOne tidak didefinisikan
    • 2. functionOne
    • 3. menghibur. log("fungsiSatu")
    • 4. undefined
    AnswerMenjawab. 1

    Pemanggilan 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

    • 1. {nama. "Yohanes", makan. f}, {nama. "Yohanes", makan. f}
    • 2. Jendela {. }, Jendela {. }
    • 3. {nama. "Yohanes", makan. f}, tidak terdefinisi
    • 4. {nama. "Yohanes", makan. f}, Jendela {. }
    AnswerMenjawab. 4

    function 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,

    1. Di ES6, fungsi panah akan menjadikan kata kunci ________5______47 sebagai cakupan leksikal. Karena objek di sekitar objek function func() {}; new func(x, y, z);_47 adalah objek var object = new (function () { this.name = "Sudheer"; })();45, fungsi var object = new (function () { this.name = "Sudheer"; })();49 akan berisi objek var object = new (function () { this.name = "Sudheer"; })();45 untuk objek function func() {}; new func(x, y, z);47

    function func() {}; new func(x, y, z);_35

    Dua solusi berikutnya telah digunakan sebelum ES6 diperkenalkan

    1. Dimungkinkan untuk membuat referensi function func() {}; new func(x, y, z);47 menjadi variabel terpisah dan menggunakan variabel baru itu sebagai pengganti kata kunci function func() {}; new func(x, y, z);47 di dalam fungsi var object = new (function () { this.name = "Sudheer"; })();49. Ini adalah praktik umum di jQuery dan AngularJS sebelum ES6 diperkenalkan

    function func() {}; new func(x, y, z);_36

    1. Fungsi var object = new (function () { this.name = "Sudheer"; })();49 dapat mengikat secara eksplisit dengan function func() {}; new func(x, y, z);47 kata kunci yang merujuk objek var object = new (function () { this.name = "Sudheer"; })();52

    function func() {}; new func(x, y, z);_37

    72. What is the output of below code?

    function func() {}; new func(x, y, z);_38

    • 1. Jello World. , John Smith
    • 2. Jello World. , Yohanes
    • 3. Halo Dunia. , John Smith
    • 4. Halo Dunia. , John
    AnswerAnswer. 3

    Dalam 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

    • 1. BENAR
    • 2. False
    • 3. Mengkompilasi kesalahan waktu
    AnswerMenjawab. 2

    Dalam 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

    • 1. Undefined
    • 2. Kesalahan referensi
    • 3. Halo selamat pagi
    • 4. batal
    AnswerAnswer. 3

    Variabel 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

    • 1. PALSU
    • 2. BENAR
    AnswerMenjawab. 1

    Meskipun 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

    • 1. Fungsi murni
    • 2. Fungsi tidak murni
    AnswerMenjawab. 2

    Meskipun 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

    • 1. [{status. "fullfilled", value. undefined}, {status. "rejected", reason. belum diartikan}]
    • 2. [{status. "terisi penuh", nilai. undefined}, Uncaught(in promise)]
    • 3. Tidak tertangkap (dalam janji)
    • 4. [Uncaught(in promise), Uncaught(in promise)]
    AnswerMenjawab. 2

    The 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

    • 1. coba blokir, Error. Pengecualian dilemparkan
    • 2. Error. Pengecualian dilemparkan
    • 3. coba blokir, Kesalahan Tidak Tertangkap. Pengecualian dilemparkan
    • 4. Uncaught Error. Exception is thrown
    AnswerAnswer. 3

    Jika 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

    Disclaimer

    The 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?

    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. .

Postingan terbaru

LIHAT SEMUA