| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Grammar_and_types | [Back] [Original] |
Get to know MDN better
JavaScript Java, C, C++ Awk, Perl, Python
JavaScript Unicode Frh ( "early" )
const Frh = "foobar";
JavaScript frh Frh
: ECMAScript (ASI)JavaScript
C++
//
/*
*/
*/
/* /* */ SyntaxError */
*/
/* /* *\/ */
JavaScript 3
JavaScript (_) ($) (09) JavaScript "A" "Z" "a" "z"
Unicode Unicode
Number_hitstemp99_name
2
let x = 42 let x = 42 ReferenceError var let undefined
let x;
console.log(x); // "undefined"
let x = 42 let x; x = 42
const undefined
const x; // SyntaxError: Missing initializer in const declaration
if (Math.random() > 0.5) {
const y = 5;
}
console.log(y); // ReferenceError: y is not defined
var
5 x x if
if (true) {
var x = 5;
}
console.log(x); // x 5
console.log(x === undefined); // true
var x = 3;
(function () {
console.log(x); // undefined
var x = "local value";
})();
var x;
console.log(x === undefined); // true
x = 3;
(function () {
var x;
console.log(x); // undefined
x = "local value";
})();
var
let const ReferenceError
console.log(x); // ReferenceError
const x = 3;
console.log(y); // ReferenceError
let y = 3;
window window. globalThis JavaScript
window frame phoneNumber iframe parent.phoneNumber
const ($)
const PI = 3.14;
let
// THIS WILL CAUSE AN ERROR
function f() {}
const f = 5;
//
function f() {
const g = 5;
var g;
}
const
const MY_OBJECT = { key: "value" };
MY_OBJECT.key = "otherValue";
const MY_ARRAY = ["HTML", "CSS"];
MY_ARRAY.push("JAVASCRIPT");
console.log(MY_ARRAY); // ['HTML', 'CSS', 'JAVASCRIPT'];
ECMAScript 8
JavaScript
let answer = 42;
answer = "Thanks for all the fish!";
JavaScript
+ JavaScript
x = " " + 42; // " 42"
y = 42 + " "; // "42 "
z = "37" + 7; // "377"
JavaScript
"37" - 7; // 30
"37" * 7; // 259
parseInt
:
parseInt
parseInt("101", 2); // 5
+ () Number()
"1.1" + "1.1"; // '1.11.1'
(+"1.1") + (+"1.1"); // 2.2
// :
JavaScript
0 ([]) (length)
3 coffees (length) 3
const coffees = ["French Roast", "Colombian", "Kona"];
:
Array Array Array
2 fish
const fish = ["Lion", , "Angel"];
console.log(fish);
// [ 'Lion', <1 empty item>, 'Angel' ]
2 "empty" undefined Array.prototype.map fish[1] undefined
(length) 3 myList[3] myList[1]
const myList = ["home", , "school"];
(length) 4 myList[0] myList[2]
const myList = [, "home", , "school"];
(length) 4 myList[1] myList[3]
const myList = ["home", , "school", ,];
JavaScript
undefined
const myList = ["home", /* */, "school", /* */, ];
2 true false
JavaScript 10
-123.4 - 123.4
(BigInt) 10 16 8 2
0 0 0o 0O8 8 0 7 0x 0X16 16 (0 9) a f A F 0xa = 0xA = 10 0xf = 0xF = 15 0b 0B2 2 0 1 n (BigInt) 0123n 0 8 0o123n 0, 117, 123456789123456789n 10 015, 0001, 0o777777777777n 8 0x1123, 0x00111, 0x123456789ABCDEFn 16 0b11, 0b0011, 0b11101001010101010101n 2
.)e E + - 1 e E
[digits].[digits][(E|e)[(+|-)]digits]
3.1415926
.123456789
3.1E+12
.1e-23
0 ({})
:
{
car myCar "Saturn" 2 getCar (carTypes("Honda")); 3 special (sales)
const sales = "";
function carTypes(name) {
return name === "" ? name : `${name}`;
}
const car = { myCar: "", getCar: carTypes(""), special: sales };
console.log(car.myCar); //
console.log(car.getCar); //
console.log(car.special); //
const car = { manyCars: { a: "", b: "" }, 7: "" };
console.log(car.manyCars.b); //
console.log(car[7]); //
(.)
const unusualPropertyNames = {
"": "",
"!": "",
};
console.log(unusualPropertyNames.""); // SyntaxError: Unexpected string
console.log(unusualPropertyNames.!); // SyntaxError: Unexpected token !
([])
console.log(unusualPropertyNames[""]); //
console.log(unusualPropertyNames["!"]); // !
foo: foo super
const obj = {
// __proto__
__proto__: theProtoObj,
// 'handler: handler'
handler,
//
toString() {
//
return `d ${super.toString()}`;
},
//
["prop_" + (() => 42)()]: 42,
};
const re = /ab+c/;
0 (") (') ()
'foo'
"bar"
'1234'
'one line \n another line'
"Joyo's cat"
String String String
String JavaScript String String length
//
console.log("Joyo's cat".length); // 10
(`) (grave accent)
Perl Python
//
`JavaScript '\n' `;
//
`JavaScript
`;
//
const name = "Lev",
time = "today";
`Hello ${name}, how are you ${time}?`;
const formatArg = (arg) => {
if (Array.isArray(arg)) {
// Print a bulleted list
return arg.map((part) => `- ${part}`).join("\n");
}
if (arg.toString === Object.prototype.toString) {
// This object will be serialized to "[object Object]".
// Let's print something nicer.
return JSON.stringify(arg);
}
return arg;
};
const print = (segments, ...args) => {
// For any well-formed template literal, there will always be N args and
// (N+1) string segments.
let message = segments[0];
segments.slice(1).forEach((segment, index) => {
message += formatArg(args[index]) + segment;
});
console.log(message);
};
const todos = [
"Learn JavaScript",
"Learn Web APIs",
"Set up my website",
"Profit!",
];
const progress = { javascript: 20, html: 50, css: 10 };
print`I need to do:
${todos}
My current progress is: ${progress}
`;
// I need to do:
// - Learn JavaScript
// - Learn Web APIs
// - Set up my website
// - Profit!
// My current progress is: {"javascript":20,"html":50,"css":10}
print(["I need to do:\n", "\nMy current progress is: ", "\n"], todos, progress);
console.log
console.log("I need to do:\n%o\nMy current progress is: %o\n", todos, progress);
"one line \n another line";
JavaScript
\0 |
|
\b |
|
\f |
|
\n |
|
\r |
|
\t |
|
\v |
|
\' |
|
\" |
|
\\ |
(\) |
\XXX |
Latin-1 3 8 XXX 0 377 \251 |
\xXX |
Latin-1 2 16 XX 00 FF \xA9 |
\uXXXX |
Unicode 4 16 XXXX \u00A9 Unicode |
\u{XXXXX} |
Unicode \u{2F804} Unicode \uD87E\uDC04 |
const quote = "He read \"The Cremation of Sam McGee\" by R.W. Service.";
console.log(quote);
He read "The Cremation of Sam McGee" by R.W. Service.
c:\temp
const home = "c:\\temp";
const str =
"this string \
is broken \
across multiple \
lines.";
console.log(str); //
JavaScript
| Web Proxy Viewer | New URL | Original Page |