일반적인 JavaScript 질문 및 답변.

9982 단어 javascriptbeginners

First, I want you to know that JavaScript is not Java. They are two very different languages. JavaScript is not a subset of Java. It is not interpreted Java. (Java is interpreted Java!). So here are a few questions and answers on JavaScript below;



1. JavaScript에 있는 다른 데이터 유형은 무엇입니까?
데이터 유형에는 두 가지 종류가 있습니다.
1) 기본 데이터 유형
2) 기본이 아닌 데이터 유형

1) Primitive Data Types:



ㅏ. 문자열: JavaScript의 문자열 유형은 텍스트 데이터를 나타내는 데 사용됩니다. 문자열은 따옴표로 작성되며 작은따옴표 또는 큰따옴표를 사용할 수 있습니다. 문자열의 각 요소는 문자열의 위치를 ​​차지합니다. 첫 번째 요소는 인덱스 0에 있고 다음 요소는 인덱스 1에 있습니다. 문자열의 길이는 그 안에 있는 요소의 수입니다. 예시:

let fruitName1 = "Apple";  // Using double quotes
let fruitName2 = 'Orange'; // Using single quotes


비. 숫자: 숫자 유형은 배정밀도 64비트 이진 형식 IEEE 754 값입니다. 2^-1074와 2^1024 사이의 부동 소수점 숫자를 저장할 수 있지만 -(2^53 − 1)에서 2^53 − 1 범위의 정수만 안전하게 저장할 수 있습니다. Number의 범위를 벗어나는 값 .MIN_VALUE에서 Number.MAX_VALUE로 +Infinity 또는 -Infinity로 자동 변환됩니다. 예시:

let x = 68.00;     // Written with decimals
let x2 = 657;        // Written without decimals


씨. 부울: 논리적 엔터티를 나타내며 참과 거짓의 두 가지 값을 가질 수 있습니다.

let x = 25;
let y = 25;
let z = 98;

(x == y)       // Returns true
(x == z)       // Returns false


디. 정의되지 않음: 값이 할당되지 않은 전역 변수입니다.

let foo;
console.log('is undefined?', foo === undefined);


이자형. Null: 개체 값이 의도적으로 없음을 나타냅니다. Null은 정의되지 않은 것처럼 전역 개체의 속성에 대한 식별자가 아닙니다. 대신 null은 변수가 개체를 가리키지 않음을 나타내는 식별 부족을 나타냅니다.

2) 기본이 아닌 데이터 유형:

ㅏ. 개체: JavaScript에서 개체는 속성 모음으로 볼 수 있습니다. 또한 이름/값 쌍의 참조 가능한 컨테이너입니다. 이름은 문자열(또는 문자열로 변환되는 숫자와 같은 기타 요소)입니다. 값은 다른 개체를 포함하여 모든 데이터 유형이 될 수 있습니다.

An object begins with {left brace and ends with }right brace. Each name is followed by :colon and the name/value pairs are separated by ,comma. Example:



const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};


2) JavaScript의 Hoisting에 대해 설명하시오.

JavaScript Hoisting refers to the process whereby the declaration of functions, variables or classes is moved to the top of their scope, prior to execution of the code.
Hoisting allows functions, variables or class to be declared before initialized. Example:



var foo; // → Hoisted variable declaration
console.log(foo); // → undefined
foo = 42; // → variable assignment remains in the same place
console.log(foo); // → 42


3) "=="와 "==="연산자의 차이점.

“==” and “===” are both comparison operators but they have a difference; the equality operator (==) checks whether its two operands are equal, returning a Boolean value. It tries to transform and compare operands which can be of various types but the strict equality operator (===) checks if its two operands are equal, returning a Boolean result. The strict equality operator always considers operands of different types to be different.

In summary, “==” convert their operands if the operand types do not match but “===” does not convert operands, it ensures that they belong to the same type and are the same value.



4) JavaScript의 암시적 유형 강제를 설명하십시오.

Implicit coersion simply refers to Javascript trying to coerce values from one data type to another (think of JavaScript automatically converting a string to a number).



5) JavaScript는 정적으로 입력되는 언어입니까 아니면 동적으로 입력되는 언어입니까?

JavaScript is a dynamically typed language.



6) JavaScript에서 NaN 속성은 무엇입니까?

NaN is a variable in global scope representing Not-A-Number and is used in a mathematical function or operation in JavaScript which cannot return a specific number.



7) 값에 의한 전달과 참조에 의한 전달에 대해 설명하십시오.

Pass by value means that a copy of the actual parameter’s value is made in memory, i.e. the caller and callee have two independent variables with the same value. If the callee modifies the parameter value, the effect is not visible to the caller.

Pass by reference (also called pass by address) means to pass the reference of an argument in the calling function to the corresponding formal parameter of the called function so that a copy of the address of the actual parameter is made in memory, i.e. the caller and the callee use the same variable for the parameter. If the callee modifies the parameter variable, the effect is visible to the caller’s variable.



8) javascript에서 즉시 호출되는 함수는 무엇입니까?

Immediately-Invoked Function Expressions (IIFE), are a common JavaScript pattern that executes a function instantly after it's defined.



9. JavaScript의 고차 함수를 설명하십시오.

고차 함수는 다른 함수를 매개변수로 받거나 함수를 값으로 반환하는 함수입니다. 매개변수로 전달되는 함수를 콜백이라고 합니다. 고차 함수는 함수를 값으로 반환합니다.

10. "이"키워드를 설명하십시오.

The keyword “this” is set to the object when a method (when a function is a member of an object) of the object is called. The 'this' keyword refers to a special property of an execution context.



11. call(), apply() 및 bind() 메서드를 설명하십시오.

The call() method allows for a function/method belonging to one object to be assigned and called for a different object. call() provides a new value of this to the function/method. With call() , you can write a method once and then inherit it in another object, without having to rewrite the method for the new object.The call() method takes arguments separately.

The apply() method allows you to call a function with a given this value and arguments provided as an array(The apply() method takes arguments as an array).
Here is the syntax of the apply() method:



fn.apply(thisArg, [args]);


bind() 메서드는 호출될 때 this가 특정 값으로 설정된 새 함수를 반환합니다. 다음은 bind() 메서드의 구문을 보여줍니다.

fn.bind(thisArg[, arg1[, arg2[, ...]]])


12. 자바스크립트에서 커링이란?

Currying is a functional programming technique which transforms a function that takes multiple arguments into a sequence of nesting functions that each take only a single argument.



13. 자바스크립트에서 Scope와 Scope Chain에 대해 설명하시오.

Scope refers to the accessibility or visibility of variables in JavaScript. Scope determines which sections of the program can access the variable and where the variable can be seen.
Three are three types of scope in JavaScript:
a. Global scope
b. Local scope and
c. Block Scope



스코프 체인

The scope chain is how Javascript looks for variables. When looking for variables through the nested scope, the inner scope first looks at its own scope. If the variable is not assigned locally, which is inside the inner function or block scope, then JavaScript will look at the outer scope of said function or block to find the variable. If Javascript could not find the variable in any of the outer scopes on the chain, it will throw a reference error.



14. JavaScript에서 클로저를 설명하십시오.

Closures are functions that have access to the variables that are present in their scope chain even if the outer function ceases to exist. Functions can be defined inside of other functions. The inner function has access to the vars and parameters of the outer function. If a reference to an inner function survives (for example, as a callback function), the outer function's vars also survive.



15. 객체 프로토타입이란 무엇입니까?

Prototypes are a powerful and very flexible feature of JavaScript, making it possible to reuse code and combine objects. Prototypes are the mechanism by which JavaScript objects inherit features from one another.

Every object in JavaScript has a built-in property, which is called its prototype. The prototype is itself an object, so the prototype will have its own prototype, making what's called a prototype chain. The chain ends when we reach a prototype that has null for its own prototype.



16. 콜백이란 무엇입니까?

A callback is a function which can be passed as parameter to other function. Callback is executed at the end of an operation, once all other operations are complete.



17. 메모이제이션이란?

Memoization is a simple but powerful trick that can help speed up our code, especially when dealing with repetitive and heavy computing functions.



18. 프로그래밍 언어에서 재귀란 무엇입니까?

Recursion is the process of defining a problem (or the solution to a problem) in terms of (a simpler version of) itself.



19. JavaScript에서 생성자 함수의 용도는 무엇입니까?

a. A constructor function is used to initialize (set values for) the object's members/properties.
b. A constructor is also used to create a new object.



20. DOM이란 무엇입니까?

The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects; that way, programming languages can interact with the page.

좋은 웹페이지 즐겨찾기