-
-
Save thinkphp/6713cc86c6c953da86936105f73c0e72 to your computer and use it in GitHub Desktop.
Javascript Questions Interview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1 '2' Number('2') | |
| function sum(a, b) { | |
| return a + b;//+ operatorul concateneaza | |
| //dubla semnificatie: prima semnificatie adunare in sens matematic, a doua semnificatie concateneaza doua string-uri | |
| } | |
| //*,/,- transforma in Number | |
| //coercion | |
| /* | |
| A: NaN | |
| B: TypeError | |
| C: "12"// | |
| D: 3 | |
| */ | |
| console.log ( sum(1,'2') ) | |
| function bark() { | |
| console.log("Woolf"); | |
| } | |
| bark.animal = 'dog' | |
| bark.culoare = 'abc' | |
| /* | |
| A: nothing, totul este ok (Correct answer) | |
| B: Syntax Error | |
| C: "woolf" este inregistrat | |
| D: ReferenceError | |
| Toate functiile in JS sunt obiecte | |
| O functie este un tip special de OBJECT | |
| */ | |
| //bark() | |
| function Person(firstname, lastname) { | |
| this.firstname = firstname | |
| this.lastname = lastname | |
| } | |
| //creeaza un obiect | |
| const member = new Person("John","Fatima") | |
| Person.prototype.getFullName = function() { | |
| return `${this.firstname} ${this.lastname}` | |
| } | |
| console.log(member.getFullName()) | |
| /* | |
| A: TypeError | |
| B: SyntaxError | |
| C: John Fatima | |
| D: undefined undefined | |
| In JS prototype este un mecanism prin care obiectele pot mosteni proprietati si metode de la alte obiecte | |
| function Person(name) { | |
| this.name = name; | |
| } | |
| const ana = new Person("Ana") | |
| const ion = new Person("Ion") | |
| Person.prototype.sayHello = function() { | |
| console.log(`Salut, sunt ${name}`) | |
| } | |
| ana.sayHello() //Salut, sunt Ana | |
| io.sayHello() //Salut, sunt Ion | |
| */ | |
| /* | |
| function Person(name) { | |
| this.name = name; | |
| } | |
| const ana = new Person("Ana") | |
| const ion = new Person("Ion") | |
| Person.prototype.sayHello = function() { | |
| console.log(`Salut, sunt ${this.name}`) | |
| } | |
| ana.sayHello() //Salut, sunt Ana | |
| ion.sayHello() //Salut, sunt Ion | |
| */ | |
| function Pers(firstname, lastname) { | |
| this.firstname = firstname; | |
| this.lastname = lastname; | |
| } | |
| //this -> global object | |
| const ob1 = new Pers("John","Fatima") | |
| const ob2 = Pers('Sarah',"Smith") | |
| console.log(ob1)// Pers{firstname: 'John', lastname: 'Fatima'} | |
| console.log(ob2)//undefined | |
| /* | |
| A: Target > Capturing > Bubbling | |
| B: Bubbling > Target > Capturing | |
| C: Target > Bubbling > Capturing | |
| D: Capturing > Target > Bubbling (Correct) | |
| || <form> | |
| \/ | |
| <div> | |
| <p> /\ | |
| || | |
| */ | |
| //Care este output-ul? | |
| let number = 0 | |
| console.log( number++ ) //posfix | |
| // 0 | |
| //returneaza valoarea care este 0 | |
| //incrementeaza valoarea care este acum 1 | |
| console.log(++number) | |
| //incrementeaza valoarea care este acum 1 si devine 2 | |
| //si dupa acea returneaza valoarea number 2 | |
| console.log( number ) | |
| /* | |
| A: 1 1 2 | |
| B: 1 2 2 | |
| C: 0 2 2 (CORRECT ANSWER) | |
| D: 0 1 2 | |
| */ | |
| function getPersonInfo(one, two, three) { | |
| console.log(one) | |
| console.log(two) | |
| console.log(three) | |
| } | |
| const person = "John" | |
| const age = 20 | |
| const abc = "asd" | |
| //valoarea primului argument este intotdeauna un ARRAY de string de valori | |
| getPersonInfo`${person} is ${age} years old` | |
| //getPersonInfo(`${abc} ${person} is ${age} years old`) | |
| //getPersonInfo(abc,person,age) | |
| /* | |
| A:"John" 20 ["", " is ", " years old"] | |
| B:[""," is ", " years old"] "John" 20 //B correct answer | |
| C: "John" ["", " is ", years old"] 20 | |
| */ | |
| //tagged template literals | |
| /* | |
| getPersonInfo( | |
| [""," is ", " years old"], | |
| "John", | |
| 20 | |
| ) | |
| Aici este cheia | |
| */ | |
| function checkAge( data ) { | |
| //verifica daca au aceeasi locatie de memorie ; compara by reference | |
| if( data === {age: 18} ) {//return False | |
| console.log("You are an adult!") | |
| } else if( data == {age: 18} ) { //return False | |
| console.log("You are still an adult!") | |
| } else { | |
| console.log("You do not have an age I guess") | |
| } | |
| } | |
| checkAge( {age: 18} ) | |
| /* | |
| A: You are an adult | |
| B: You are still an adult | |
| C: YOu do not... | |
| */ | |
| function getAge() { | |
| 'use strict' | |
| abcd = 20 | |
| console.log( abcd ) | |
| } | |
| //getAge() | |
| // | |
| /* | |
| A: 20 | |
| B: undefined | |
| C: ReferenceError // | |
| D: TypeError | |
| */ | |
| //the rest paramenter (...abc) | |
| //un array este un object | |
| function function_name( ...abc ) { | |
| console.log(typeof abc) | |
| console.log(abc) | |
| } | |
| function_name( 20, 309, 101, 203, "asdsa","asdasd") | |
| /* | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment