본문 바로가기

javascript50

[Svelte] Template Syntax 이번에는 markup 영역에서 조건문, 반복문 등을 사용하는 방법에 대해 살펴보겠습니다. #if 다음 예제와 함께 조건문의 사용에 대해 살펴봅시다. {#if score >= 90} Grade: A {:else if score >= 80} Grade: B {:else} Grade: C {/if} 조건문의 경우 아주 간단하죠? 몇 가지 문법적 요소만 기억하시면 쉽게 사용하실 수 있습니다. #each 이번엔 반복문의 사용에 대해 살펴봅니다. {#each nums as num} {num} {/each} {#each nums as num, idx} {idx}: {num} {/each} {#each persons as person (person.name)} {person.name}, {person.age} {/ea.. 2022. 12. 10.
[Svelte] Getting Started with SvelteKit ※ 2022.12.01 오랫만에 Svelte를 다시 접해보니 많은 것들이 변해 있더라고요. 그래서 현 시점을 기준으로 다시 정리를 해봅니다. Create Project SvelteKit을 사용하여 프로젝트를 생성해보겠습니다. 원래는 yarn을 사용했었지만, yarn도 modern yarn으로 버전업이 되면서 많은 것이 달라졌습니다. 가장 큰 변화는 node_modules를 사용하지 않는 것입니다. 이로 인하여 당연시 해당 폴더를 참조하던 것들이 동작을 제대로 못하게 되버렸습니다. 변경해서 사용할 수는 있지만 추가적인 노력이 들어가야 하고, VSCode 역시 추가 조작을 해야만 되는 상황이라 현재로서는 npm을 쓰시는 것이 조금 더 편하게 사용하실 수 있을 거에요. $ npm create svelte@la.. 2022. 12. 1.
[JavaScript] Map Object The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value may be used as either a key or a value. A key should be unique. Create a Map Object The Map() constructor creates a new Map object. const map = new Map(); // Map(0) {} const map = new Map([ ['key1', 'value1'], ['key2', 'value2'] ]); // Map(2) {'key1' => 'value1', 'key2' => 'value2'} const map =.. 2022. 7. 14.
[JavaScript] Set Object The Set object lets you store unique values of any type, whether primitive values or object references. Create an Set Object The Set constructor creates a Set object. const set = new Set(); // Set(0) {} const set = new Set([1, 2, 3, 3]); // Set(3) {1, 2, 3} const set = new Set('Hello'); // Set(4) {'H', 'e', 'l', 'o'} Set objects consider that all NaNs are the same. console.log(NaN === NaN); // f.. 2022. 7. 13.
[JavaScript] String Object The String object is used to represent and manipulate a sequence of characters. Create a String The string constructor creates an instance by type coercion an argument into a string. const strObj = new String(); const strObj = new String('HoYa'); const strObj = new String(123); // '123' If we don't use the new operator, it is converted to a string and returned. String(1); // '1' String(NaN); // .. 2022. 7. 10.
[JavaScript] RegExp Object The RegExp object is used for matching text with a pattern. It introduced PCRE from ES3. Create a Regular Expression RegExp instance can be created by the constructor or literal notation. Please see the 3 ways below. const re = /ab+c/i; const re = new RegExp('ab+c', 'i'); const re = new RegExp(/ab+c/, 'i')); The pattern syntax is below. /PATTERN/FLAG / symbol means to start and end. In other wor.. 2022. 7. 9.
[JavaScript] Date Object The Date object represents a single moment in time in a platform-independent format. It contains a Number that represents milliseconds since 1970/01/01 00:00:00 UTC. There is a difference in the result representation depending on the browser environment and node.js environment. Date Constructor There are 4 ways to create a Date instance. new Date() It returns a date instance with the current dat.. 2022. 7. 9.
[JavaScript] Math Object Math is a standard built-in object that has only static properties and static methods for mathematical constants and functions. It works with the Number type and doesn't work with the BigInt type. Math Property E This property is Euler's constant. Math.E; // 2.718281828459045 LN2 This property is a natural logarithm of 2. Math.LN2; // 0.6931471805599453 LN10 This property is a natural logarithm .. 2022. 7. 8.
[JavaScript] Number Object The Number object is a standard built-in object that is useful when handling the primitive type of numbers. Number Definition We can create an instance whose type is the Number using the Number() constructor. const numObj = new Number(); // [Number: 0] const numObj = new Number(10); // [Number: 10] const numObj = new Number('10'); // [Number: 10] const numObj = new Number('test'); // [Number: Na.. 2022. 7. 7.
[JavaScript] Array Arrays in JS are sparse array that is not continuously connected in memory. Compared to a typical array, accessing the index is fast, and inserting/deleting is slow. Neither JS arrays' length nor its elements' types are fixed. Create Arrays There are 4 ways to create arrays. Array Literal const arr1 = [1, 2, 3]; const arr2 = ["apple", 2, "carrot", 4]; Array Constructor const arr = new Array(3); .. 2022. 7. 6.
[JavaScript] Class From ES6, JS has class. JS is a prototype-based language. Therefore, classes in JS are slightly different from those in other object-oriented languages. A class is basically a data type that collected variables and methods for similar purposes. Class Declaration A statement or expression can declare classes. Both anonymous and named declarations are possible in expression. class Person {} const .. 2022. 7. 1.
[JavaScript] Object Objects of JS are a collection of related data and/or functionality. Objects can have multiple primitive types of values. The primitive type of value is immutable, but the object type of value is mutable. Property An object is a set of zero or more properties, and the property consists of a key and a value. If the value of the property is a function, it is called a method. Key Key can be string .. 2022. 6. 26.