“If two operands of the same type and value, then === returns true, and! == false”
JavaScript: The Good Parts
if(someVariableExists)
x = false
if(someVariableExists)
x = false
anotherFunctionCall();
if(someVariableExists) {
x = false;
anotherFunctionCall();
}
if(someVariableExists) {
x = false;
}
anotherFunctionCall();
if(2 + 2 === 4) return 'nicely done';
JSLint JavaScript . , . , . JSLint - . . .”
– JSLint Documentation
<p>And now you know my favorite kinds of corn. </p>
<script type="text/javascript" src="path/to/file.js"></script>
<script type="text/javascript" src="path/to/anotherFile.js"></script>
</body>
</html>
for(var i = 0; i < someArray.length; i++) {
var container = document.getElementById('container');
container.innerHtml += 'my number: ' + i;
console.log(i);
}
var container = document.getElementById('container');
for(var i = 0, len = someArray.length; i < len; i++) {
container.innerHtml += 'my number: ' + i;
console.log(i);
}
var arr = ['item 1', 'item 2', 'item 3', ...];
var list = '<ul><li>' + arr.join('</li><li>') + '</li></ul>';
, ( ) .
( join()), .
— James Padolsey, james.padolsey.com
« , , .»
— Douglas Crockford
var name = 'Jeffrey';
var lastName = 'Way';
function doSomething() {...}
console.log(name); // Jeffrey -- or window.name
var DudeNameSpace = {
name : 'Jeffrey',
lastName : 'Way',
doSomething : function() {...}
}
console.log(DudeNameSpace.name); // Jeffrey
// Cycle through array and echo out each name.
for(var i = 0, len = array.length; i < len; i++) {
console.log(array[i]);
}
setInterval(
"document.getElementById('container').innerHTML += 'My new number: ' + i", 3000
);
setInterval(someFunction, 3000);
with (being.person.man.bodyparts) {
arms = true;
legs = true;
}
being.person.man.bodyparts.arms = true;
being.person.man.bodyparts.legs= true;
var o = being.person.man.bodyparts;
o.arms = true;
o.legs = true;
var o = new Object();
o.name = 'Jeffrey';
o.lastName = 'Way';
o.someFunction = function() {
console.log(this.name);
}
var o = {
name: 'Jeffrey',
lastName = 'Way',
someFunction : function() {
console.log(this.name);
}
};
var o = {};
, . .
— dyn-web.com, http://ww.dyn-web.com/tutorials/obj_lit.php
var a = new Array();
a[0] = "Joe";
a[1] = 'Plumber';
var a = ['Joe','Plumber'];
« JavaSript — , . : — . — .
Douglas Crockford
var someItem = 'some string';
var anotherItem = 'another string';
var oneMoreItem = 'one more string';
var someItem = 'some string',
anotherItem = 'another string',
oneMoreItem = 'one more string';
var someItem = 'some string'
function doSomething() {
return 'something'
}
var someItem = 'some string';
function doSomething() {
return 'something';
}
ECMAScript ( , , -, do-while, continue, break, return, throw) . . , , . , , .
for(key in object) {
if(object.hasOwnProperty(key)) {
...then do something...
}
}
for(prop in object) if (object.hasOwnProperty(prop)) {
//...
}
function TimeTracker(){
console.time("MyTimer");
for(x=5000; x > 0; x--){}
console.timeEnd("MyTimer");
}
— ?
— , !
— !
— , !
— Sponge Bob Square Pants
var response = JSON.parse(xhr.responseText);
var container = document.getElementById('container');
for(var i = 0, len = response.length; i < len; i++) {
container.innerHTML += '<li>' + response[i].name + ' : ' + response[i].email + '</li>';
}
<script type="text/javascript" language="javascript">
...
</script>
Source: https://habr.com/ru/post/175283/
All Articles