次ã«ãæååã«æ³¨ç®ãã¾ããããããã°ã©ãã³ã°ã§ã¯ãããã¹ãã®æçãããå¼ã³ã¾ãããã®è¨äºã§ã¯ãæååã®ä½æãæååå ã®å¼ç¨ç¬¦ã®ã¨ã¹ã±ã¼ããæååã®çµåãªã©ãJavaScript ãå¦ã¶ä¸ã§å®ã«ç¥ã£ã¦ããã¹ãæååã«é¢ããå ±éäºé ããã¹ã¦è¦ã¦ããã¾ãã
åæç¥è: HTMLããã³CSS ã®åºç¤ãçè§£ãã¦ãããã¨ã å¦ç¿ææ:è¨èã¯ã³ãã¥ãã±ã¼ã·ã§ã³ã®å¤§é¨åãæ ãã人é¡ã«ã¨ã£ã¦ãã¨ã¦ã大åãªãã®ã§ããã¦ã§ãã¯æ å ±ã®å ±æãã³ãã¥ãã±ã¼ã·ã§ã³ãã§ããããã«è¨è¨ãããå¤§è¦æ¨¡ãªæåãã¼ã¹ã®åªä½ã§ãã®ã§ãããã§ä½¿ç¨ãããè¨èãæä½ã§ããã¨ä¾¿å©ã§ãã HTML ã¯ããã¹ããæ§é åãã¦æå³ã¥ããã CSS ããããã«ä½è£ãæ´ãããã¨ãå¯è½ã«ãããã㦠JavaScript ã¯æååãæä½ããããããã®æ©è½ãæä¾ãã¦ãã¾ããç¬èªã®æ¨æ¶æãçæããããé©åãªã©ãã«ã表示ããããè¨èãä¸¦ã¹æ¿ãããã¨ãã£ããã¨ãè¡ãã¾ãã
ãã®ã³ã¼ã¹ã®ããã¾ã§ç¤ºããããã°ã©ã ã®ã»ã¨ãã©ãã¹ã¦ããä½ããã®æååæä½ãå«ãã§ãã¾ãã
æååã®å®£è¨æååã¯æåã®è¦ãç®ã§ã¯æ°å¤ã¨åãããã«æ±ããã¾ãããæ·±ãæãä¸ããã¨ããã¤ãã®é¡èãªéããè¦ãã¦ãã¾ããåºæ¬çãªè¡ããã©ã¦ã¶ã¼ã®éçºè ã³ã³ã½ã¼ã«ã«å ¥åãã¦æ £ãããã¨ããå§ãã¾ãããã
å§ãã«ã次ã®è¡ãå ¥åãã¦ãã¾ãããã
const string = "é©å½ã¯ãã¬ãã§ã¯æ¾éãããªãã";
console.log(string);
æ°åã®ã¨ãã¨åãããã«ã夿°ã宣è¨ããæååã®å¤ã§åæåãããã®å¤ãè¿ãã¦ãã¾ããããã§ä¸ã¤ç°ãªãã®ã¯ãæååãæ¸ãã¨ãã«ã¯å¤ãå¼ç¨ç¬¦ã§å²ãå¿ è¦ãããã¨ãããã¨ã§ãã
ãããè¡ããªãã£ãããå¼ç¨ç¬¦ã®ä¸æ¹ãæ¸ãè½ã¨ãããããã¨ãã¨ã©ã¼ãçºçãã¾ãã以ä¸ã®è¡ãå ¥åãã¦ã¿ã¦ãã ããã
const badString1 = ããã¯ãã¹ãã§ã;
const badString2 = 'ããã¯ãã¹ãã§ã;
const badString3 = ããã¯ãã¹ãã§ã';
ãããã®è¡ã¯åä½ãã¾ãããå¼ç¨ç¬¦ã§å²ã¾ãã¦ããªãããã¹ãã¯ã夿°åãããããã£åãäºç´èªãªã©ã¨è§£éãããããã§ãããã©ã¦ã¶ã¼ãå¼ç¨ç¬¦ã§å²ã¾ãã¦ããªãããã¹ããèªèã§ããªãå ´åãã¨ã©ã¼ãçºçãã¾ãï¼"missing; before statement" ãªã©ï¼ããã©ã¦ã¶ã¼ãæååã®éå§ãæ¤åºã§ãã¦ãï¼2 ã¤ç®ã®å¼ç¨ç¬¦ããªãããã«ï¼çµäºãæ¤åºã§ããªãã£ãå ´åã "unterminated string literal" ã¨ã©ã¼ãå ±åããã¾ããããããã°ã©ã ã§ãã®ãããªã¨ã©ã¼ãçºçããã®ã§ããã°ãæååããã¹ã¦èª¿ã¹ã¦ãå¼ç¨ç¬¦ã®æ¬ è½ããªããã¨ã確èªãã¦ãã ããã
以ä¸ã¯ã string
ã¨ãã夿°ãå®ç¾©ãã¦ããã°åä½ãã¾ãã試ãã¦ã¿ã¾ãããã
const badString = string;
console.log(badString);
badString
ã¨ãã夿°ã« string
ã¨ãã夿°ã®å¤ãè¨å®ããã¾ãã
JavaScript ã§ã¯ãæååãå²ãå¼ç¨ç¬¦ã¨ãã¦ãåä¸å¼ç¨ç¬¦ã¨äºéå¼ç¨ç¬¦ã使ç¨ãããã¨ãã§ãã¾ãã以ä¸ã®ã©ã¡ãã®ä¾ãæ£ããåãã¾ãã
const single = 'åä¸å¼ç¨ç¬¦';
const double = "äºéå¼ç¨ç¬¦";
const backtick = `éå¼ç¨ç¬¦`;
console.log(single);
console.log(double);
console.log(backtick);
æååã®éå§ã¨çµäºã«ã¯ãåãæåã使ç¨ããªããã°ã¨ã©ã¼ã¨ãªãã¾ãã
const badQuotes = 'ããã¯è¨±ããã¾ããï¼";
ä¸éå¼ç¨ç¬¦ã§å®£è¨ãããæååã¨äºéå¼ç¨ç¬¦ã§å®£è¨ãããæååã¯åãã§ãã©ã¡ãã使ç¨ãããã¯å人ã®ç°å¢è¨å®ã«ããã¾ãããä¸ã¤ã®ã¹ã¿ã¤ã«ãé¸ãã§ã³ã¼ãã§ä¸è²«ãã¦ä½¿ç¨ããã®ãè¯ãç¿æ £ã§ãã
éå¼ç¨ç¬¦ã使ç¨ãã¦å®£è¨ãããæååã¯ããã³ãã¬ã¼ããªãã©ã«ã¨å¼ã°ããç¹æ®ãªæååã§ããã»ã¨ãã©ã®ç¹ã§ããã³ãã¬ã¼ããªãã©ã«ã¯æ®éã®æååã¨åãã§ãããããã¤ãã®ç¹å¥ãªç¹æ§ãããã¾ãã
ãã³ãã¬ã¼ããªãã©ã«ã§ã¯ã JavaScript ã®å¤æ°ãå¼ã ${ }
ã§å²ãã§å
¥ãããã¨ãã§ãããã®çµæãæååã®ä¸ã«åãè¾¼ã¾ãã¾ãã
const name = "Chris";
const greeting = `Hello, ${name}`;
console.log(greeting); // "Hello, Chris"
åãææ³ã使ç¨ãã¦ã2 ã¤ã®å¤æ°ãçµåãããã¨ãã§ãã¾ãã
const one = "Hello, ";
const two = "how are you?";
const joined = `${one}${two}`;
console.log(joined); // "Hello, how are you?"
ãã®ããã«æååãçµåãããã¨ãé£çµã¨å¼ã³ã¾ãã
ã³ã³ããã¹ãã§ã®é£çµå®éã«ä½¿ç¨ããã¦ããé£çµãè¦ã¦ã¿ã¾ãããã
<button>æ¼ãã¦ã</button>
<div id="greeting"></div>
const button = document.querySelector("button");
function greet() {
const name = prompt("ããªãã®ååã¯?");
const greeting = document.querySelector("#greeting");
greeting.textContent = `${name} ãããããã«ã¡ã¯ãã¯ããã¾ãã¦ï¼`;
}
button.addEventListener("click", greet);
ããã§ã¯ window.prompt()
颿°ã使ç¨ãã¦ãããã¹ããå
¥åã§ãããããã¢ãããã¤ã¢ãã°ã表示ããã¦ã¼ã¶ã¼ã«ãã£ã¦å
¥åãããæååã夿°ã¸ããã®å ´å㯠name
夿°ã¸æ ¼ç´ãã¦ãã¾ããããã¦ããã®ååãä¸è¬çãªæ¨æ¶ã¡ãã»ã¼ã¸ã«æ¿å
¥ããæååã表示ãã¾ãã
${}
ã¯éå¸¸ã®æååã§ã¯ãªãããã³ãã¬ã¼ããªãã©ã«ã使ç¨ãããã¨ãã§ãã¾ããéå¸¸ã®æåå㯠+
æ¼ç®åã使ç¨ãã¦é£çµãããã¨ãã§ãã¾ãã
const greeting = "Hello";
const name = "Chris";
console.log(greeting + ", " + name); // "Hello, Chris"
ããããé常ããã³ãã¬ã¼ããªãã©ã«ã使ç¨ããã¨ãããèªã¿ãããã³ã¼ãã«ãªãã¾ãã
const greeting = "Hello";
const name = "Chris";
console.log(`${greeting}, ${name}`); // "Hello, Chris"
æååå
ã«å¼ãå«ãã
åç´ãªå¤æ°ã¨åæ§ã«ã JavaScript ã®å¼ããã³ãã¬ã¼ããªãã©ã«ã«å«ãããã¨ãã§ãããã®çµæãçµæã«å«ã¾ãã¾ãã
const song = "Fight the Youth";
const score = 9;
const highestScore = 10;
const output = `I like the song ${song}. I gave it a score of ${
(score / highestScore) * 100
}%.`;
console.log(output); // "I like the song Fight the Youth. I gave it a score of 90%."
è¤æ°è¡ã®æåå
ãã³ãã¬ã¼ããªãã©ã«ã¯ãã½ã¼ã¹ã³ã¼ãã®æ¹è¡ãå°éããã®ã§ã次ã®ããã«è¤æ°è¡ã«ã¾ãããæååãæ¸ããã¨ãã§ãã¾ãã
const newline = `One day you finally knew
what you had to do, and began,`;
console.log(newline);
/*
One day you finally knew
what you had to do, and began,
*/
éå¸¸ã®æååã使ç¨ãã¦åçã®åºåãããããã«ã¯ãæååã®ä¸ã«æ¹è¡æå (\n
) ãè¨è¼ããå¿
è¦ãããã¾ãã
const newline = "One day you finally knew\nwhat you had to do, and began,";
console.log(newline);
/*
One day you finally knew
what you had to do, and began,
*/
ãããªãä¾ã¨é«åº¦ãªæ©è½ã®è©³ç´°ã«ã¤ãã¦ã¯ããã³ãã¬ã¼ããªãã©ã«ã®ãªãã¡ã¬ã³ã¹ãã¼ã¸ãåç §ãã¦ãã ããã
æååã«å¼ç¨ç¬¦ãå«ããã«ã¯æååã®å é ã¨æ«å°¾ã示ãããã«å¼ç¨ç¬¦ã使ç¨ãããã¨ãã§ãã¾ãã®ã§ãå®éã®å¼ç¨ç¬¦ãæååã«å«ããã«ã¯ã©ãããã°ããã§ãããããããã¯åä½ãã¾ããã
const badQuotes = "She said "I think so!"";
ä¸è¬çãªãªãã·ã§ã³ã® 1 ã¤ã¯ãæååã宣è¨ããããã«ä»ã®æåã®ããããã使ç¨ãããã¨ã§ãã
const goodQuotes1 = 'She said "I think so!"';
const goodQuotes2 = `She said "I'm not going in there!"`;
ããä¸ã¤ã®ãªãã·ã§ã³ã¯ãåé¡ã®å¼ç¨ç¬¦ãã¨ã¹ã±ã¼ããããã¨ã§ããæåãã¨ã¹ã±ã¼ãããã¨ãããã¨ã¯ããã®æåãã³ã¼ãã®ä¸é¨ã§ã¯ãªããããã¹ãã¨ãã¦èªèãããããã«ãããã¨ãæå³ãã¦ãã¾ãã JavaScript ã§ãããè¡ãã«ã¯ãæåã®ç´åã«ããã¯ã¹ã©ãã·ã¥ãç½®ãã¾ãã試ãã¦ã¿ã¦ãã ããã
const bigmouth = 'I\'ve got no right to take my placeâ¦';
console.log(bigmouth);
ãã®ä»ã®ç¹æ®æåãæ¿å ¥ããå ´åãåãæè¡ã使ãã¾ãã詳細ã¯ã¨ã¹ã±ã¼ãã·ã¼ã±ã³ã¹ãåç §ãã¦ãã ããã
æ°å¤ã¨æååã§ã¯ãæååã¨æ°åãçµã¿åãããã¨ã©ããªãã®ã§ãããããã³ã³ã½ã¼ã«ã§è©¦ãã¦ã¿ã¾ãããã
const name = "ããã³ã ";
const number = 242;
console.log(name + number); // "ããã³ã 242"
ã¨ã©ã¼ãè¿ãã¨æãããããã¾ããããããã¯ãã¾ãåä½ãã¾ããæ°å¤ãæååã¨ãã¦ã©ã®ããã«è¡¨ç¤ºãããã¹ããã¯ããªãå³å¯ã«å®ç¾©ããã¦ããã®ã§ããã©ã¦ã¶ã¼ã¯èªåçã«æ°å¤ãæååã«å¤æãã 2 ã¤ã®æååãé£çµãã¾ãã
æååã«å¤æãããæ°å¤å¤æ°ãã¾ãã¯æ°å¤ã«å¤æãããæåå夿°ãããå ´åã以ä¸ã® 2 ã¤ã®æ§æã使ç¨ãããã¨ãã§ãã¾ãã
Number()
颿°ã¯æ¸¡ããããã®ãã¹ã¦ãæ°å¤ã«å¤æãã¾ããæ¬¡ã®ä¾ãå®è¡ãã¦ã¿ã¾ãããã
const myString = "123";
const myNum = Number(myString);
console.log(typeof myNum);
// number
String()
颿°ã¯éã«ã弿°ãæååã«å¤æãã¾ãã試ãã¦ã¿ã¦ãã ããã
const myNum2 = 123;
const myString2 = String(myNum2);
console.log(typeof myString2);
// string
ãã®çææ¹æ³ã¯ç¶æ³ã«ãã£ã¦ã¯ã¨ã¦ã便å©ã§ããä¾ãã°ãã¦ã¼ã¶ã¼ããã©ã¼ã ã®ããã¹ããã£ã¼ã«ãã«æ°åãå
¥åããå ´åãå
¥åãããå¤ã¯æååã§ãããããããã®æ°åã使ã£ã¦è¨ç®ãããå ´åãæ°å¤ã«ããªããã°ãªãã¾ããããããªæã¯ Number()
ã«ä»»ãã¾ããããããã¯å®éã«æ°åå½ã¦ã²ã¼ã ã§ä½¿ç¨ããæ¹æ³ã§ãã
以ä¸ãJavaScript ã§æååã®ããåºæ¬çãªãã¨ã説æãã¾ãããæ¬¡ã®è¨äºã§ã¯ãJavaScript ã§æååã«å©ç¨ã§ããçµã¿è¾¼ã¿ã¡ã½ããã¨ããããã使ç¨ãã¦æååãæãéãã®å½¢ã«æä½ãããã¨ãã§ããæ¹æ³ãè¦ã¦ããã¾ãã
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4