StoryCode

'JavaScript, ECMAScript'에 해당되는 글 17건

  1. 문법 기본
  2. 자바스크립트 역사.
  3. Count, 카운트
  4. 실수를 정수로 바꾸는 방법
  5. Hoisting.호이스팅
  6. 자바스크립트.변수.모니터링워처
  7. 한글 받침 구별법

문법 기본

JavaScript, ECMAScript
반응형

'use strict'

 

BABEL 

 

JavaScript let varname = 123;

var 는 쓰지 말 것. Hoisting 이라고 변수를 먼저 사용후 선언해도 되는 방식.

const bigint = 1234....n
TypeScript let varname:integer = 123;

MS 개발.
Javascript + Type ( Data )
ES5 + ES6 포함.

BABEL 로 Javascript 로 변환

 

String 합치기

Console.log ("Answer ${varname}");

 

class Student
{
  constructor(name, age, enrolled, score)
  {
    this.name = name;
    this.age = age;
    this.enrolled = enrolled;
    this.score = scorre;
  }
}

const students = [
  new Student('A', 29, true,  45),
  new Student('B', 28, false, 85),
  new Student('C', 30, true,  95)
];

{
  const result = students.find(function(student, index) {
    return student.score === 90;
  };

  // 조건에 맞는 1 개의 Row 만 리턴. find
  const result = students.find(student => student.score === 90);

  // 조건에 맞는 여러개의 Row 을 Array 로 리턴 - filter
  const result = students.filter((student) => student.enrolled);

  // 45, 85, 95. 특정 컬럼을 리턴 - map
  const result = students.map((student) => student.score);

  // 조건에 맞는 경우가 있으면 True 리턴. some
  const result = students.some(student => student.score < 90);

  // 모두 조건에 맞으면 True 리턴. every
  const result = students.every(student => student.score < 90);

  // 배열 하나씩 처리할 때 쓴다. 배열의 값을 누적할 때 쓴다. - reduce
  const result = students.reduce((prev, curr) => prev + curr.score, 0);
  // 0 을 안 넣으면, 처음에는 prev = 배얼[0], curr = 배열[1] 이 넘어간다. 두번째에는 prev = 리턴값, curr = 배열[2]
  // 0 을 넣으면,    처음에는 prev = 0,       curr = 배열[0] 이 넘어간다. 리턴은 누적을 한다.

  // 응용. 50 점 넘는 점수를 join 하기.
  const result = students.map((student) => student.score)
                         .filter((score) => score >= 50)
                         .join();

  const result = students.map((student) => student.score)
                         .sort((a, b) => a-b) // Plus / Minus 에 따라서 정렬순서 정의
                         .join();

  console.log(result);
}

AJAX - XMLHttpRequest Object : Request & Respone - (new) fetch() API

 

반응형

'JavaScript, ECMAScript' 카테고리의 다른 글

import, export  (0) 2021.09.28
CORS.ajax.fetch.어떻게 해도 CORS 가 발생할 경우  (0) 2021.08.31
자바스크립트 역사.  (0) 2020.09.21
Count, 카운트  (0) 2020.03.09
실수를 정수로 바꾸는 방법  (0) 2020.03.04

자바스크립트 역사.

JavaScript, ECMAScript
반응형
1993 Netscape MOSAIC Web Browser 정적 HTML + CSS
1994 Netscape Navigator Scriping 언어추가 시도. Java + Scheme 스크립트
1994.09 Scheme 스크립트 = Mocha = LiveScript Interpreter
1995 LiveSript + Java 유명세 = Javascript
1996 MS 가 Netscape 사 Reverse Engineering. Javascript 를 JScript 롤 이름만 바꿈.
1996.11 Netscape 가 ECMA 와 협업해 표준 시도.
1997 ECMAScript 1 출시
1999 ECMAScript 3 출시. Error Handling. === 연산자 추가
2000 ECMAScript 4. 본격 언어화
2000 MS IE 표준화 선언. ECMAScript 4 개발 무시. ECMAScript 발전 중단
2004 FireFox 출시 + "ECMAScript4 를 ActionScript3 Tamarin 표준 제안했으나 거부". 3사 경쟁=개발자 표준달라 고생.
2004 Jesse James Garrett Ajax 도입.
2005 개발자 커뮤니티. jquery vs dojo vs mootools. = 표준 상관안해도 되게 해줌.
2008 Chrome 출시. Just In Time 컴파일 방식
2008.07 브라우저 협의회출시
2009 ( 매우 중요 ) ECMAScript 5
2015 ( 매우 중요 ) ECMAScript 6. default parameter, class, arrow function, const, let
2019 ECMAScript 10. jquery 등 불필요.


브라우저별 ECMAScript 엔진
CHROME - V8. NodeJS 와 ELETRON 에서도 활용
FireFox   - SpiderMonkey
Safari     - JSCore
MSEdge - CHakra
Opera    - Carakan
Adobe Flash - Tamarin

ECMAScript 최신버전을 Javascript 로 Transcompiler 로 ECMASccript  5 나 6로 변환 = BABEL
SPA - Single Page Application. React, Angular, Vue.

V8 Engine 
  NODE.js - V8 Javascript 기반 back-end 서비스 구현.
  Mobile 
  ELECRON - Desktop App 개발

Web Assembly - C, CPP 동작
반응형

'JavaScript, ECMAScript' 카테고리의 다른 글

CORS.ajax.fetch.어떻게 해도 CORS 가 발생할 경우  (0) 2021.08.31
문법 기본  (0) 2020.10.07
Count, 카운트  (0) 2020.03.09
실수를 정수로 바꾸는 방법  (0) 2020.03.04
Hoisting.호이스팅  (0) 2020.02.12

Count, 카운트

JavaScript, ECMAScript
반응형

index.html
0.00MB
script.js
0.00MB
style.css
0.00MB

반응형

'JavaScript, ECMAScript' 카테고리의 다른 글

문법 기본  (0) 2020.10.07
자바스크립트 역사.  (0) 2020.09.21
실수를 정수로 바꾸는 방법  (0) 2020.03.04
Hoisting.호이스팅  (0) 2020.02.12
자바스크립트.변수.모니터링워처  (0) 2020.02.01

실수를 정수로 바꾸는 방법

JavaScript, ECMAScript
반응형

참조 : https://www.geeksforgeeks.org/how-to-convert-a-float-number-to-the-whole-number-in-javascript/

 

 

 

How to convert a float number to the whole number in JavaScript?

There are various methods to convert float number to the whole number in JavaScript.

  1. Math.floor (floating argument): Round off the number passed as parameter to its nearest integer in Downward direction.
    Syntax:Math.floor(value)

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 4.59;

       var x = 4.59;

       var z = Math.floor(x);

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 4.59 is 4
  2. Math.ceil (floating argument): Return the smallest integer greater than or equal to a given number.
    Syntax:Math.ceil(value)

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 4.59;

       var x = 4.59;

       var z = Math.ceil(x);

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 4.59 is 5
  3. Math.round (floating argument): Round a number to its nearest integer.
    Syntax:Math.round(var);

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 4.59;

       var x = 4.59;

       var z = Math.round(x);

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 4.59 is 5
  4. Math.trunc (floating argument): Return the integer part of a floating-point number by removing the fractional digits.
    Syntax:Math.trunc(value)

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 4.59;

       var x = 4.59;

       var z = Math.trunc(x);

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 4.59 is 4
  5. parseInt (floating argument): Accept the string and convert it into an integer.
    Syntax:parseInt(Value, radix)

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 3.54;

       var x = 3.54;

       var z = parseInt(x);

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 3.54 is 3
  6. double bitwise not (~~) operator: Round a number to towards zero. If the operand is a number and it’s not NaN or Infinity.
    Syntax:~~value

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 4.59;

       var x = 4.59;

       var z = ~~x;

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :


    Converted value of 4.59 is 4
  7. bitwise OR (|) operator: Round a number to towards zero.
    Syntax:var = value | 0;

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 5.67;

       var x = 5.67;

       var z = x | 0;

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 5.67 is 5
  8. Using shift (>>) operator: Round a number to towards zero.
    Syntax:var = value >> 0;

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 5.63;

       var x = 5.63;

       var z = x >> 0; 

       //it is same as we are dividing the value by 1.

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 5.63 is 5
  9. Using unsigned shift (>>>) operator Round a number to towards zero.
    Syntax:var = value >>> 0;

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 5.68;

       var x = 5.68;

       //it is same as we are dividing the value by 1.

       var z = x >>> 0; 

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 5.68 is 5
  10. By subtracting the fractional part
    Syntax:var = val - val%1;

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 5.48;

       var x = 5.48;

       var z = x - x%1;

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 5.48 is 5
  11. Using XOR (^) operator
    Syntax:var = value ^ 0;

    filter_none

    edit

    play_arrow

    brightness_4

    <script>

      //float value is 5.49;

       var x = 5.49;

       var z = x ^ 0;

       document.write("Converted value of " + x + " is " + z);

    </script>

    Output :

    Converted value of 5.49 is 5

 

반응형

'JavaScript, ECMAScript' 카테고리의 다른 글

자바스크립트 역사.  (0) 2020.09.21
Count, 카운트  (0) 2020.03.09
Hoisting.호이스팅  (0) 2020.02.12
자바스크립트.변수.모니터링워처  (0) 2020.02.01
한글 받침 구별법  (0) 2019.04.15

Hoisting.호이스팅

JavaScript, ECMAScript
반응형

참조) https://gmlwjd9405.github.io/2019/04/22/javascript-hoisting.html

Compile Phase 1 에서 선언이 필요한 부분을 검색하는 것을 말한다.

 

Hoisting 대상

1. var 변수 선언

2. 함수 선언문

Hoisting 비 대상

1. let 변수 선언

2. 함수 표현식

var variable = "Yes"; let variable = "Yes";
# 함수 선언문
function func()
{
}
# 함수 표현식
var foo2 = function()
{
}
   
   
   
   
반응형

'JavaScript, ECMAScript' 카테고리의 다른 글

자바스크립트 역사.  (0) 2020.09.21
Count, 카운트  (0) 2020.03.09
실수를 정수로 바꾸는 방법  (0) 2020.03.04
자바스크립트.변수.모니터링워처  (0) 2020.02.01
한글 받침 구별법  (0) 2019.04.15

자바스크립트.변수.모니터링워처

JavaScript, ECMAScript
반응형

function print(t) {
  var c = document.getElementById('console');
  c.innerHTML = c.innerHTML + '
' + t;
}

// Demo
var varw = (function (context) {
  return function (varName, varValue) {
    var value = varValue;
  
    Object.defineProperty(context, varName, {
      get: function () { return value; },
      set: function (v) {
        value = v;
        print('Value changed! New value: ' + value);
      }
    });
  };
})(window);

varw('varWatch'); // Declare
print(varWatch);
varWatch = 456;
print(varWatch);

print('---');

varw('otherVarWatch', 123); // Declare with initial value
print(otherVarWatch);
otherVarWatch = 789;
print(otherVarWatch);

 

 

결과)

undefined
Value changed! New value: 456
456
---
123
Value changed! New value: 789
789

 

참조) https://stackoverflow.com/questions/1759987/listening-for-variable-changes-in-javascript

반응형

'JavaScript, ECMAScript' 카테고리의 다른 글

자바스크립트 역사.  (0) 2020.09.21
Count, 카운트  (0) 2020.03.09
실수를 정수로 바꾸는 방법  (0) 2020.03.04
Hoisting.호이스팅  (0) 2020.02.12
한글 받침 구별법  (0) 2019.04.15

한글 받침 구별법

JavaScript, ECMAScript
반응형

[참조] https://tk2rush90.blog.me/221085154547

[참조] http://blog.naver.com/PostView.nhn?blogId=azure0777&logNo=221414175631&categoryNo=0&parentCategoryNo=0&viewDate=¤tPage=1&postListTopCurrentPage=1&from=postView&userTopListOpen=true&userTopListCount=5&userTopListManageOpen=false&userTopListCurrentPage=1

 

- 자음 유니코드

let uni = 12593; // 유니코드를 문자로 변환하는 함수 12593~12622

String.fromCharCode();

while(uni) {

   let kor = String.fromCharCode(uni);

   console.log("kor : " + kor + " - uni);

   if(kor === "ㅎ") break;

   uni++;

}

 

 

- 모음 유니코드 :  12623 ~ 12643

문자 내에서 초성, 중성, 종성으로 쓰이는 자모음은 위 표와 같으며, 종성은 숫자 1마다, 중성은 29마다, 초성은 589마다 값이 변한다는 사실을 알 수 있다. 이 내용을 토대로 한글 문자를 분리하는 기능을 만들어보자.

 

- 한글 문자 분리

function getConstantVowel(kor) {
    const f = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ',
               'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ',
               'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];
    const s = ['ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ',
               'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ', 'ㅛ', 'ㅜ',
               'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ'];
    const t = ['', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ',
               'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ',
               'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ',
               'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];

    const ga = 44032;
    let uni = kor.charCodeAt(0);

    uni = uni - ga;

    let fn = parseInt(uni / 588);
    let sn = parseInt((uni - (fn * 588)) / 28);
    let tn = parseInt(uni % 28);

    return {
        f: f[fn],
        s: s[sn],
        t: t[tn]
    };
}

- 받침 유무 ( ~가/이 구분용 )

function checkBatchimEnding(word) {
  if (typeof word !== 'string') return null;
 
  var lastLetter = word[word.length - 1];
  var uni = lastLetter.charCodeAt(0);
 
  if (uni < 44032 || uni > 55203) return null;
 
  return (uni - 44032) % 28 != 0;
}


 

반응형

'JavaScript, ECMAScript' 카테고리의 다른 글

자바스크립트 역사.  (0) 2020.09.21
Count, 카운트  (0) 2020.03.09
실수를 정수로 바꾸는 방법  (0) 2020.03.04
Hoisting.호이스팅  (0) 2020.02.12
자바스크립트.변수.모니터링워처  (0) 2020.02.01