What means this jquery code with two values in a variable?
You're declaring two variables and the first one has a value.
var target = $(e.target), article;
is the same as:
var target = $(e.target);
var article;
This not jQuery related -- rather "vanilla" Javascript.
Helpful material: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var
Syntax of variable in javascript
No this is not the same. This would be the same:
var option_1 = 0, option_2 = 0;
In your case #2 has option_1
set to 0
, and option_2
being undefined
.
What is the difference between a single comma-separated variable declaration, and multiple declarations?
The comma separated declaration is just a short hand. Executing-wise there's no difference. But it can help reduce the size of your javascript file if you are declaring a lot of variables.
You can even do:
var a = 1, b = 'string', c = new Date();
Javascript variable definition - clarification
It's creating 3 variables
var line = {}; // creates an object
var lines = []; // creates an array
var hasmore; // undefined
Elements and functions separated by commas
It's just a bunch of variable declarations/initializations, separated by commas. It's the same as:
var _t = this;
var _resetProperties;
var _add_html5_events;
var _remove_html5_events;
var _stop_html5_timer;
var _start_html5_timer;
var _attachOnPosition;
var _onplay_called = false;
var _onPositionItems = [];
var _onPositionFired = 0;
var _detachOnPosition;
var _applyFromTo;
var _lastURL = null;
var _lastHTML5State;
I don't like to mix initializations with declarations like this. It is messy and not very readable. If anything, group your declarations (without values), and only group initializations if they are related. It doesn't functionally change the code, it only makes it a bit smaller (and harder to read in cases).
Code inside javascript function separated with commas instead of semicolons
In javascript, when declaring new variables with the var
keyword, you can separate each declaration by commas. Which allows you to only use the var
keyword once. Its a sort of short-hand.
For example:
var self = this,
options = self.options,
title = options.title || "No Title",
uiChatbox = (self.uiChatbox = $('<div></div>')).appendTo(document.body)
Is the same as:
var self = this;
var options = self.options;
var title = options.title || "No Title";
var uiChatbox = (self.uiChatbox = $('<div></div>')).appendTo(document.body);
Related Topics
Password-Check Directive in Angularjs
How to Populate the Options of a Select Element in JavaScript
How to Update React Context from Inside a Child Component
Script Tag in Angular2 Template/Hook When Template Dom Is Loaded
How to Import a CSS File in a React Component
How to Make a JSON Call to an Url
How to Access Xhr Responsebody (For Binary Data) from JavaScript in Ie
Jquery - Create Hidden Form Element on the Fly
Why Are Objects Not Iterable in JavaScript
What the Difference Between .Click and .Change on a Checkbox
Dynamic Variables Names in JavaScript
Selecting Multiple Classes with Jquery
Angular2 Component's "This" Is Undefined When Executing Callback Function
JavaScript || or Operator with an Undefined Variable
Fetching Values from Email in Protractor Test Case
Event Listener for When Element Becomes Visible