JS 공부를 시작하겠습니다.

JAVASCRIPT 기초 지식을 배우다

Learn to appreciate yourself and celebrate small wins--자신을 계속 격려하는 데 도움이 된다

Javascript 기본 사항


1. 머리말


JavaScript("JS"약칭)는 웹 사이트에 상호작용을 추가할 수 있는 성숙한 동적 프로그래밍 언어이다.Brendan Eich(Mozilla 프로젝트, Mozilla 기금회와 Mozilla 회사의 공동 창시자)가 발명한 것이다. 여기를 클릭하여 Javascript지금까지의 온전한 역사를 알아보자.

2.안녕하세요,세상!


console.log("Hello World!");

//console.log() is one of the javascript inbuilt function which allows us to print anything in the code at the output.

3. 사용자 입력


prompt는 자바스크립트의 내장 함수로 사용자의 입력을 입력할 수 있는 대화상자를 만듭니다.그러나 이것은 브라우저 콘솔에만 적용됩니다.이런 입력을 받아들이는 방법은 건의하는 것이 아니라 그 존재를 배우는 것이다.
prompt("What is your name?");

4. 변수


Javascript는 Variables라는 값을 저장하는 용기를 포함합니다.
var myName = "Jaswanth";
var myAge = 19;
let myPlace = "Rajahmundry";
.
.
.
//many things were there to know about these variables, so go through the above link.

5. JS의 데이터 유형


서로 다른 유형의 데이터는 서로 다른 이름의 이름이다.Data types 예를 들어 정수, 문자열, 문자, 부동점, 부어.advancedArray에서 더 많습니다.우리는 걸으면서 배운다.
그 외에 너는 알아야 한다type coercion
var integer= 723; // It is a Integer(number);
var deciamalNumber = 200.76349; //It is a Float(decimal number)
var str = "Javascript is a scripting language."  //It is String(text)
let bool = True //Boolean (True or False)

6.조건문


if 문장::실행 부분 코드의 조건을 충족시키는지 확인하십시오.
if-else: 이 동작은if문장의 조건이true인 것처럼 코드는if나else에 포함된 부분을 실행합니다. 그렇지 않으면 실행됩니다
else 문장에 첨부하다.
중첩 if::만약if문장이true라면if문장의 다음if문장을 검사합니다.
if-else if-else::if문 이외의if문이 다른if문을 검사할 때true가 아닌 것과 같습니다.
if문
// if statement-syntax

var myAge = 19;
if(check_condition){
    //if true execute statements inside this
}


//if statement - example

if (myAge >=18){
    console.log("you are above 18);
}
그렇지 않으면
//if-else  - syntax

if(check_condition){
    //if true execute statements inside this
}
else{
    //if false execute statements inside this
}


//if-else  - example

var myAge = 16;
if (myAge >= 18){
    console.log("you are above 18);  //does not execute this
}
else{
    console.log("you are below 18);  //executes and prints "you are below 18"
}
중첩 if
//syntax

if(check_condition-1){
    //if true
    if(check-condition-2){
        //if true
        if(check-condition-3){
            ... // this goes on till every check condition is true
        }
    }
}

* if any of the check condition is false it comes out and executes the rest of the statements below that if statement. *

//example
var myAge = 19;
var myName = "Jaswant";
if(myAge >= myAge){     //condition is true
    if (myName == "Jaswanth"){ //condition is false
        console.log("You are Jaswanth");
    }
    console.log("You are",myAge);
}

output -
You are 19

순환하다


개발자는 자신의 일을 되풀이하지 말라는'건조'원칙을 따른다.그래서 그들은 순환, 함수, 알고리즘, 모델 등을 이용한다.이제 우리는 순환이 무엇인지 알 수 있다.
순환이란 순환 문장의 조건이false로 변할 때까지 여러 번 한 조의 문장을 운행하는 것을 말한다.
다양한 유형의 루프를 보려면 여기를 참조하십시오.
  • for loop
  • for-syntax
    for(INITIALIZATION, CHECK_CONDITION, INCREMENT/DECREMENT){
        //set of statements to be executed
    }
    
    예컨대
    for(let i=0; i<5; i++){
        console.log("hello..");
    }
    
    // let i = 0  -->  initialize i = 0;
    // i<5 --> checks wheather the value of i is less than 5
    // i++ --> increment the value of i by 1 value(i=i+1)
    //This loop runs for 5 times and print "hello.."
    hello..
    hello..
    hello..
    hello..
    hello..
    
  • while
  • 문법
    //
    while(CHECK_CONDITION){
        //set of statements to be executed
    }
    
    예컨대
    var i = 0;
    while(i<5){
        console.log("hello..");
        i++;
    }
    
    //This loop runs 5 times and print "hello.."
    hello..
    hello..
    hello..
    hello..
    hello..
    
    

  • do while - 이것은 특수한 유형의while 순환으로 이런 순환에서 조건이 만족하지 않아도 최초의 순환은 적어도 한 번 운행한다.
  • do-while  - syntax
    do{
        //set of statements to be executed
    }while(CHECK_CONDITION);
    
    //do-while  - example
    let k=10;
    do{
    console.log(k);
    k++;
    }while(k<0)
    
    //output -
    10
    

    기능


    함수는 입력을 전달하고 출력을 가져와서 특정한 함수를 실행하는 데 사용됩니다.우리는 서로 다른 입력을 사용하여 이 함수를 여러 번 호출하고 같은 임무를 수행하며 매번 다른 출력 (다른 입력) 을 얻을 수 있다.
    //defining a function - syntax
    function FUNCTION_NAME(PARAMETERS){    //parameters are the optional inputs which were received by the function to do something with them and give output
        //set of statements to be executed when function is called
    }
    
    //function calling - syntax
    FUNCTION_NAME(ARGUMENTS); //argumentss are the optional values which were to be passed to functions as inputs for that function
    
    //example
    function printName(name){  //name is parameter
        console.log("Hi " + name);
    }
    
    //calling a function
    printName("Tanay");     // Tanay is an argument --> this print :  "Hi Tanay"
    printName("Akanksha");     // Akanksha is an argument--> this print :  "Hi Akanksha"
    

    프로젝트 작성

  • 로 전환repl(repl 탐색, 이것은 재미있는 인터넷 응용이다).
  • 현재 리플 초보자라면 새 계정을 만드세요.
  • 새 리플을 열고 node를 선택하십시오.노드 아래의 js.js
  • 이제 노드를 사용하여 Javascript에 들어갑니다.js 컨트롤러.
  • 곤혹스러워하지 마라. 습관이 되려면 시간이 필요하다.여가 시간에 리플을 탐색합니다.
  • 테스트 항목


    이제 간단한 자바스크립트와 nodejs 프로젝트에 들어갑니다.이 간단한 프로젝트에서 우리는 간단한 명령행 인터페이스 테스트를 구축했다.최종적으로 프로젝트를 진행할 때 우리는 우리의 프로젝트를 구축할 것이다.
    이 프로젝트를 통해 우리는 무엇을 배울 수 있습니까?
  • 입력 가져오기("readline sync"npm 패키지 사용)
  • 인쇄 출력
  • 연산자 사용
  • if와if-else의 용법
  • for순환의 용법
  • 수조, 사전 등 기본 데이터 구조의 사용
  • 이 프로젝트를 만드는 목적은 Marvel에 대한 작은 테스트를 만드는 것입니다

    사용자 입력을 얻기 위해 "readline sync"라는 npm 패키지를 사용했습니다.


    라이브러리에서 이 패키지를 사용하려면 다음 코드를 입력하여 프로젝트에 사용할 수 있도록 하십시오.


    var readlineSync = require('readline-sync')
    
    현재 유저의 이름을 입력하고 환영 메시지를 출력합니다.\n'은(는) 도피 역할입니다.strings의 이스케이프 문자를 확인합니다.
    var playerName = readlineSync.question("Enter your name: ");
    console.log("Welcome to the quiz ",playerName+"\n");
    
    유저의 점수를 초기화합니다
    var playerScore = 0;
    
    질문 3개array를 포함하는 견본을 만듭니다objects.
    const generalQuiz = [
        {
            question: "Who is the prime minister of india?",
            a: "Tanay Pratap",
            b: "Bumrah",
            c: "Narendra Modi",
            d: "Dhoni",
            correctAnswer: "c"
    
        },
        {
            question: "Who is the president of america?",
            a: "Jaswanth",
            b: "James Cameron",
            c: "Kamala Harris",
            d: "John Beiden",
            correctAnswer: "d"
        },
        {
            question: "Which is the largest continent?",
            a: "Asia",
            b: "Africa",
            c: "South America",
            d: "Europe",
            correctAnswer: "a"
    
        },
    ]
    
    와, 우리는 수조와 대상을 수조의 모든 항목으로 사용합니다.현재 우리는 우리의 유저를 위해 이 문제들을 인쇄해야 한다.그래서 우리는 지금 for 순환을 사용한다.
    우리는 for순환을 사용하여 모든 문제를 교체해야 한다. 답이 정확한 상황에서만 우리는 유저의 점수에 1을 더할 수 있다.
    // we declare function so that the function playQuiz takes in different objects but conducts and evaluate quiz
    
    function playQuiz(quiz){
        for (let i = 0; i < quiz.length; i++)
        {
            console.log(`${i + 1}. ${quiz[i].question}`);
            console.log(`          a: ${quiz[i].a}`);
            console.log(`          c: ${quiz[i].b}`);
            console.log(`          b: ${quiz[i].c}`);
            console.log(`          d: ${quiz[i].d}`);
            var answer = readlineSync.question("Answer: ");
            console.log("\n");
    
            //now validate answer
            if (answer.toLowerCase() == quiz[i].correctAnswer){
            playerScore = playerScore + 1;
            }
        }
        return playerScore;
    }
    
    현재, 유저가 정확하게 대답할 때마다 점수가 증가합니다.
    이제 드디어 사용자의 점수를 출력해 냈습니다.
    let finalScore = playQuiz(generalQuiz); // here we called the playQuiz function and stored the final score of the player in finalScore variable.
    
    console.log("Woohooo!!, you scored "+finalScore);   // printing final score.
    

    출력



    예!!CLI 프로젝트를 완료했으므로 단순하지만 기본 지식을 더욱 효과적으로 구축할 수 있습니다.
    자바스크립트의 기초 지식을 배웠으면 좋겠어요.

    위 코드 게임 퀴즈의 REPL 링크 | 퀴즈 코드


    JAVASCRIPT 리소스 탐색

  • MDN DOCS
  • Eloquent Javascript book

  • You don't know javascript
  • 귀하의 피드백은 이 문서를 개선하는 데 도움이 될 것입니다❤


    문서가 마음에 드시면 | | Github |[email protected]

    좋은 웹페이지 즐겨찾기