*window.alert().document.write()doucument.getElementById("demo").innerHTMLconsole.log("gdgdg");Try itdocument.getElementById("demo").innerHTML = 5 + 6;lastName = "Doe";lastname = "Peterson"; var cars = ["Saab", "Volvo", "BMW"]; // Arrayvar x = {firstName:"john", lastName:"doe"};var x = 16 + "Volvo";var x = 16 + 4 + "Volvo"; var x = "Volvo" + 16 + 4; Result: Volvo164 left기준 rightperson["lastName"];
function myFunction() { carName = "Volvo";}var 이런거 안스고 걍쓰면 함수안에서 선언해도 글로벌 변수onchange An HTML element has been changed onclick The user clicks an HTML element onmouseover The user moves the mouse over an HTML element onmouseout The user moves the mouse away from an HTML element onkeydown The user pushes a keyboard key onload The browser has finished loading the page
Mouse over me!while (myNumber != Infinity) { ar x = 2 / 0; // x will be Infinity var y = -2 / 0; // y will be -Infinity var x = 100 / "Apple"; // x will be NaN (Not a Number)(123).toString();var x = 9.656; x.toExponential(2); // returns 9.66e+0 x.toExponential(4); // returns 9.6560e+0 x.toExponential(6); // returns 9.656000e+0 var x = 9.656; x.toFixed(0); // returns 10 x.toFixed(2); // returns 9.66 x.toFixed(4); // returns 9.6560 x.toFixed(6); // returns 9.656000 var x = 9.656; x.toPrecision(); // returns 9.656 x.toPrecision(2); // returns 9.7 x.toPrecision(4); // returns 9.656 x.toPrecision(6); // returns 9.65600 x.valueOf();
x = true; Number(x); // returns 1x = false; Number(x); // returns 0x = new Date(); Number(x); // returns 1404568027739 x = "10"Number(x); // returns 10 x = "10 20"Number(x); // returns NaN parseInt 쓸 때 스트링이랑 같이있는 숫자들 중 숫자만 쏙 뽑아옴var x = Number.MAX_VALUE; 제일 큰 숫자 리턴jquery dom tree 접근http://www.sqler.com/387425후손과 ㅇㅇ ㅇㅇ자식 > 자식은 한단계 아래의 놈만 후손은 모든 아래에 놈 다 검사ㅇㅇ + ㅇㅁ : ㅇㅇ다음의 형제요소가 ㅇㅁ인 놈을 반환ㅇㅇ ~ ㅇㅁ : ㅇㅇ를 제외한 다음에 형제요소가 ㅇㅁ인놈을 반환 $("#content").css("background", "yellow");$(function(){ $("label").each(function(index){ if($.trim($(this).text()) == "기타"){ $(this).after("<input type='text' name='opinion' />"); } });ar points = [40, 100, 1, 5, 25, 10]; points.sort(function(a, b){return a - b}); 기본 sort는 스트링인데 숫자를 스트링으로 sort하면 문제가 생긴다.var points=[40,100,1,5,22];points.sort(function(a,b){return 0.5-Math.random()});for (x in person) { text += person[x]; }String(123) // returns a string from a number literal 123 String(100 + 23) // returns a string from a number from an expressionx.toString()(123).toString()(100+23).toString()Date().toString() // returns Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)var str = "Visit W3Schools"; var n = str.search(/w3schools/i); search는 포지션 리턴한다. var str = "Visit W3Schools!"; var n = str.search("W3Schools");처음 포지션 리턴 var str = "Visit Microsoft!"; var res = str.replace(/microsoft/i, "W3Schools"); The result in res will be: Visit W3Schools!/ddd/i -> case insensitive/e/.exec("The best things in life are free!"); Since there is an "e" in the string, the output of the code above will be: e특정패턴의 스트링을 찾은다음 발견된 텍스트를 리턴한다. try{if(x>100)throw "too high"}catch(err){ "input is" + err;}
<script>var x = 15 * 5;debugger;document.getElementById("demo").innerHTML = x;</script>디버거 다음 라인은 실행 안한다.
Math.random(); 0~1min, max roundceil : nearest integerMath.floor() 버림Math.E // returns Euler's number Math.PI // returns PI Math.SQRT2 // returns the square root of 2 Math.SQRT1_2 // returns the square root of 1/2 Math.LN2 // returns the natural logarithm of 2 Math.LN10 // returns the natural logarithm of 10 Math.LOG2E // returns base 2 logarithm of E Math.LOG10E // returns base 10 logarithm of E 1470274224420 Dates written as numbers, specifies the number of milliseconds since January 1, 1970, 00:00:00.Thu Aug 04 2016 10:30:24 GMT+0900<script> var d = new Date();document.getElementById("demo").innerHTML = d; </script>
99년 5월 24일 11시 33분 30초getDay()가 숫자를 리턴하는 것 같다.getTime() Get the time (milliseconds since January 1, 1970)In JavaScript, arrays use numbered indexes. In JavaScript, objects use named indexes.var fruits = ["Banana", "Orange","Apple", "Mango"]; document.getElementById("demo").innerHTML = fruits.join(" * "); Banana * Orange * Apple * Mangovar fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.shift();orange apple mangovar fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.unshift("Lemon"); delete fruits[0]; // Changes the first element in fruits to undefineddelete쓰면 undefined hole을 남기기 때문에 팝이나 쉬프트를 쓸 것을 권장함fruits.splice(2, 0, "Lemon", "Kiwi"); add new items to an array두번째 파라미터 0은 얼마나 remove할 것인가를 나타냄fruits.splice(2, 0, "Lemon", "Kiwi"); var myChildren = myGirls.concat(myBoys);var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var citrus = fruits.slice(3); apple, mangofruits.slice(1,3) [1,3) 개폐 구간orange,lemon
x = 3.14; // This will not cause an error. myFunction();function myFunction() { "use strict"; y = 3.14; // This will cause an error (y is not defined)}var 없이 하면 global변수로 선언되는데 strict모드에서는 이게 허용 안되나보다mistyping a variable name creates a new global variable. In strict mode, this will throw an error, making it impossible to accidentally create a global variable. Variable and function names written as camelCase Global variables written in UPPERCASE (We don't, but it's quite common) Constants (like PI) written in UPPERCASE Hyphens are not allowed in JavaScript names. ex)font-size
Don't Use new Object() Use {} instead of new Object() Use "" instead of new String() Use 0 instead of new Number() Use false instead of new Boolean() Use [] instead of new Array() Use /()/ instead of new RegExp() Use function (){} instead of new Function() function myFunction(a) { var power = 10; return a * power;}return;a*power; 로 알아들음 그래서 undefined됨for (var i = 0; i < 10; i++) { // some code}document.getElementById("demo").innerHTML = i;이거 10으로 나옴 Bad Code: var i;for (i = 0; i < arr.length; i++) { Better Code: var i;var l = arr.length;for (i = 0; i < l; i++) {왜냐면 조건문 돌 때마다 length property를 계속 접근하기 때문에 Delay JavaScript Loading Putting your scripts at the bottom of the page body, lets the browser load the page first. While a script is downloading, the browser will not start any other downloads. In addition all parsing and rendering activity might be blocked. The HTTP specification defines that browsers should not download more than two components in parallel. An alternative is to use defer="true" in the script tag. The defer attribute specifies that the script should be executed after the page has finished parsing, but it only works for external scripts. If possible, you can add your script to the page by code, after the page has loaded:
json : web server to page var x = document.forms["myForm"]["fname"].value;onsubmit="return validateForm()" method="post">Name: <form action="demo_form.asp" method="post"> <input type="text" name="fname" required> <input type="submit" value="Submit"></form>꼭 뭔가 써야하는 칸 input id="id1" type="number" min="100" max="300" required>if (inpObj.checkValidity() == false) { document.getElementById("demo").innerHTML = inpObj.validationMessage; } else { document.getElementById("demo").innerHTML = "Input OK";http://www.w3schools.com/js/js_validation_api.asp<input id="id1" type="number" max="100"> if (document.getElementById("id1").validity.rangeOverflow) { txt = "Value too large"; } JavaScript Objects are Mutable Objects are mutable: They are addressed by reference, not by value.If person is an object, the following statement will not create a copy of person:var x = person; // This will not create a copy of person.The object x is not a copy of person. It is person. Both x and person is the same object.Any changes to x will also change person, because x and person are the same object.
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};delete person.age; // or delete person["age"];
Möchten Sie kostenlos Ihre eigenen Notizen mit GoConqr erstellen? Mehr erfahren.