Using momentjs-timezone in Postman

External libraries can be executed in postman if CDN equivalent of these libraries are available.

You can get CDN in equivalent from websites like: https://cdnjs.com/

Now to use momentTZ in postman, copy the below code into script section and execute it once and then comment out:

This will store the CDN equivalent of momentTZ and momentJS libraries to environment variables.

pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data-2012-2022.min.js", (mtzErr, mtzRes) => {
pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js", (mjsErr, mjsRes) => {
//you have to initialize the momentjs to make momenttz work so we are storing both into a variable
pm.environment.set("momentjs", mjsRes.text());
pm.environment.set("momenttz", mtzRes.text());
})
})

Now you initiate the libraries in either of the two approaches:

First Approach:

Now comment out the above code you don’t need it anymore. Now you can use momenttz anywhere in your collection’s script sections as :

eval(pm.environment.get("momentjs"));
eval(pm.environment.get("momenttz"));
console.log(this.moment.utc().tz("America/Los_Angeles", "UTC").format())

in this approach, the libraries are initialized in the local scope, so if you want to use them again then you have to run the 3 lines of code again in other script sections whenever it’s used.

Second approach:

new Function triggers function in the global scope. so you just have to execute the first two lines only ones in your collection run and it will be available globally throughout:

Add in first scripts pre-request script:

(new Function(pm.environment.get("momentjs")))();
(new Function(pm.environment.get("momenttz")))();

Now you can use momentTZ library anywhere as :

console.log(moment.utc().tz("America/Los_Angeles", "UTC").format())

😀 😬 😁 😂 😃 😄 😅

Postman trick and tips: How to run a specific iteration data from Newman

There is no inbuilt way to specify a specific iteration row to be executed using Newman, but can be done using Powershell or by using Newman as a library.

The approaches are as below

Powershell:

here we read the actual csv file in the current directory using import csv

Then considers only row 1..2 , if you just want 1 row you can change $a[1..2] to $[1]

$a= Import-Csv .\a.csv
$a[1..2] | Select-Object * | export-csv -Path .\temp.csv -NoTypeInformation
newman run .\test.postman_collection.json -d .\temp.csv

As library:

here we read and split the csv as we want using csv parser and then write it back to a temp file as csv using csv-stringify library.

First, install:

npm install csv
npm install fs
npm i fs-extra
npm install newman

Then use the below code

const newman = require('newman'); // require newman in your project
const stringify = require('csv-stringify')
const parse = require('csv-parse/lib/sync')
const fs = require("fs")
// call newman.run to pass `options` object and wait for callback
let data = fs.readFileSync('./a.csv',
{ encoding: 'utf8', flag: 'r' });
data = parse(data, {
columns: true,
    skip_empty_lines: true
})
console.log(data)
//index doesn't consider header so 0 is first data row
stringify(data.slice(0, 2), {
header: true
}, function (err, output) {

    fs.writeFileSync("temp.csv", output);

    newman.run({
collection: require('./test.postman_collection.json'),
reporters: 'cli',
iterationData: "./temp.csv"
}, function (err) {
if (err) { throw err; }
console.log('collection run complete!');
});
})

How to restart the browser in protractor-cucumber framework or protractor-jasmine

The problem at hand:

https://sqa.stackexchange.com/questions/42235/how-to-restart-browser-in-protractor-cucumber-framework-or-protractor-jasmine

Solution:

You are trying to access an element instance that was created using the previous browser instance. The workflow is as follow,

  1. You imported the page object instance at the start of the spec using require
  2. A browser instant is created in the onPrepare
  3. Using that instance your page object model gets the element object
  4. But on next ‘It’ the browser restarts but the page object instance remains the same
  5. So when you try to interact with the element, you are getting session ID of non-existing browser.

Solution:

As given in your code, you have your page object as a javascript property, than a function

So what you could do is, reinitiate the page object whenever you restart the browser.

This could be done using npm decahe module: https://www.npmjs.com/package/decache

So whenever, you restart the browser reinitiate the module using below command:

//import in top of the spec
var decache = require('decache');
//reinitiate where browser is restarted
decache('../pageobjects/stage1.js');
stage1 = require('../pageobjects/stage1.js');

So your final code:

'use strict';
var decache = require('decache');
let stage1 = require('../pageobjects/stage1.js');

describe('Validate stage 1 and 2 behaviour', function () {
    beforeEach(async function () {        
await browser.waitForAngularEnabled(false);
decache('../pageobjects/stage1.js');
stage1 = require('../pageobjects/stage1.js');
});

    it('Validate that error message in all fields given uploaded {Regression} {Smoke} {Sanity}', async function () {
await stage1.goto()
await stage1.sendValue('hi')
await browser.sleep(5000)
});

Note:

This works even if the page object is defined as a function

For protractor-cucumber add the same in before hook :

you should add the hook in the step definition file itself and not in separate hook.js:

"use strict";
let {Given,Before} = require('cucumber');
let decache = require('decache');
let stage1 = require('../pageobjects/stage1.js');
Before(async function (scenario) {
decache('../pageobjects/stage1.js');
stage1 = require('../pageobjects/stage1.js');
await browser.sleep(4000)
});
 Given('I navigates to google', async() => {
await stage1.goto()
});

Protractor Data-Driven Testing

Now Drive your test using test data

Now you can drive your protractor tests using CSV data:

Demo CSV: (just copy it to notepad and save as 1.csv)

a,b,c
1,2,3
1,5,6
2,4,6

Install csv-parser node module:

run it under the protractor project so that it will be installed as project’s local module ( Run the command where the package.json file is present)

npm install csv-parse

Output after parsing:

This module will parse the csv as below column as the key and value as the value on the specific row

Data-driven testing:

'use strict';
//use fs to read file
let fs = require('fs');
//use csv-parse sync to parse the file : https://csv.js.org/parse/
const parse = require('csv-parse/lib/sync');
//read the csv file
let a = fs.readFileSync('1.csv');
//parse the csv file
const testdata = parse(a, {
columns: true,
skip_empty_lines: true
})
console.log(testdata);
describe('Validate dfsfdsf 1 behaviour', function () {
for (let i of testdata) {
it('test {Regression} {Sanity} {Smoke}', async function () {
console.log(i);
console.log(i.a);
console.log(i.b);
console.log(i.c);
expect(Number(i.a) + Number(i.b)).toBe(Number(i.c))
});
}
});

Ignore below steps:

Deprecated:

npm package:

https://www.npmjs.com/package/csv-parser-sync-plus-promise

Usage:

importing:

let parser = require('csv-parser-sync-plus-promise')

Use as sync:

let a=parser.readCsvSync('')

Use as Promise:

let b=parser.readCsvPromise('')
it('test {Regression} {Sanity} {Sanity}', async function () {
console.log(await b);
});

Protractor test:

Use the demo csv ‘1.csv’

'use strict';
let parser = require('csv-parser-sync-plus-promise')
let testdata=parser.readCsvSync('<full_path>/1.csv');
describe('Validate dfsfdsf 1 behaviour', function () {

for(let i of testdata){
it('test {Regression} {Sanity} {Sanity}', async function () {
console.log(i.a);
console.log(i.b);
console.log(i.c);
expect(Number(i.a)+Number(i.b)).toBe(Number(i.c))
});
}
});

Output:

Protractor-cucumber Framework

Install dependencies:

  • cucumber : npm install cucumber (If protractor was installed locally else use npm install -g cucumber). Both protractor and cucumber should be in same scope.
  • cucumber-html-reporter: npm install cucumber-html-reporter — save-dev
  • chai: npm install chai
  • protractor-cucumber-framework: npm install — save-dev protractor-cucumber-framework

My package.json:

you can directly use the package.json and install all dependencies by placing the file under your test project and just running

npm install

package.json:

{
"name": "Test",
"version": "1.0.0",
"description": "Test framework for project Test",
"main": "conf.js",
"keywords": [
"test"
],
"author": "Praveen David Mathew",
"license": "ISC",
"dependencies": {
"chai": "^4.2.0",
},
"devDependencies": {
"cucumber": "^6.0.5",
"cucumber-html-reporter": "^5.1.0",
"protractor-cucumber-framework": "^6.2.0"
}
}

Now create chai expect global keyword:

Protractor uses jasmine out of the box, so when you are using the custom framework the jasmine expect class won’t work.

You have to use another assertion class , we are using chai.

We can use chai expect class by importing it in each step definition

'use strict';
expect = require('chai').expect;

This would be hectic, so work around is to declare expect as global in a separate file.

My chaiAssertions.js:

'use strict';
// Configure chai
global.expect = require('chai').expect;

Create Hook.js:

Hooks are just another stepdefinition file you can name it anything you want. A hook is identified using the keyword After and Before

Here i created a Hook.js file to get screenshot if scenario fails:

hook.js:

var { After, Before } = require('cucumber');
// Asynchronous Promise
After(async function(scenario) {
if (scenario.result.status === 'failed') {
const screenShot = await browser.takeScreenshot();
this.attach(screenShot, "image/png");
}
});

So after each scenario , the code inside after get executed. Which will take screenshot of scenario.result.status is failed.

Now my conf.js

'use strict';
exports.config = {
directConnect: true,
//Running chrome 
Capabilities: { browserName: 'chrome'
},
//point spec to feature file , my feature file was under feature folder
specs: ['feature/*.feature'],
//set framework options
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
//just maximizing window before testing
onPrepare: function(){
browser.waitForAngularEnabled(true);
browser.driver.manage().window().maximize();
} ,
//Create html report 
onComplete: () => {
var reporter = require('cucumber-html-reporter');
var options = {
theme: 'bootstrap',
jsonFile: './results.json',
output: './results.html',
reportSuiteAsScenarios: true,
launchReport: true,
metadata: {
"App Version":"0.3.2",
"Test Environment": "STAGING",
"Browser": "Chrome 54.0.2840.98",
"Platform": "Windows 10",
"Parallel": "Scenarios",
"Executed": "Remote"
},
output: './report/cucumber_report.html',
};
reporter.generate(options);
},
//set cucumber options
cucumberOpts: {
require: ['./testsuites/*.js','./commons/chaiAssertions.js','./commons/hooks.js'],
strict: true,
format: [], //don't put 'Pretty' as it is depreciated
'dry-run': false,
compiler: [],
format: 'json:results.json', //make sure you are not using multi-capabilities
},
SELENIUM_PROMISE_MANAGER: false,
};

Here, i point to the feature file using the property specs: [‘feature/*.feature’],

and glues it to the step definition using cucumberopts> require:

There is no one to one mapping between feature and step definition, the framework automatically finds the step definition that contains the definition for the step from provided step definitions(.js files) in the require field.

Now write feature file:

test.feature

Feature: Google search
Scenario Outline: Log in with given API
Given I navigates to google
And searches for '
'
Then I should see ''
Examples:
|input|this|
|test|pass|
|test2|fail|

Now write step definition:

step.js:

var { Given } = require('cucumber');
Given('I navigates to google', async function () {
await browser.get('https://www.google.com/');
});
Given('searches for {string}', async function (searchValue) {
await element(by.css('input[role="combobox"]')).sendKeys(searchValue)
});
Given('I should see {string}', async function (expectedValue) {
expect(expectedValue).to.equal('pass')
});

so here we are using just Given as during runtime Given ,when then etc will be ignored and only the string after that will be considered

So, even if our feature file has And searches for ‘input’ , we can write step definition as Given(‘searches for {string}’.

Note that we are not using regular expressions to get parameters but the data type.

you might have seen in other tutorials , Given( /^searches for (\w+)$/ ). Its simpler to use the format i have used Given(‘searches for {string}’. Both the approaches works works fine.

Now run the scripts:

protractor conf.js

Report:

Report will be generated under report folder

Framework zip:

Just download and run npm install

To execute , run the command protractor conf.js

https://github.com/praveendvd/Protractor_cucumber_PoC.git

Creating HTML reports for protractor

Note: I have found an easier and better report for protractor by sauce lab use that report instead:

Read about the new report at: https://medium.com/@praveendavidmathew/protractor-best-html-report-d548d1460c36

But still, you can continue reading and see any of the features would be useful for you:

First, let us see why need reporting

Imagine you have written thousands was of wonderful test cases and you have put up it in CI/CD pipeline. You must be feeling proud right? and here the news that the first test runs for the suites you have written will run over the night and you get all excited.

Next day you come to the office and sees the below console logs:

And you have no clue what passed, what failed because the execution got interrupted and was not completed.

Printing test status and logs after each test-case execution:

Add the below code to the protractor config file:

This enables real-time reporting, allowing to print errors onto console without having to wait for the test suite to finish executing.

exports.config = {
onPrepare: function(){
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
}
}));
}
}

To make this work we need to install jasmine-spec-reporter

npm i jasmine-spec-reporter

Output:

So we can know when something goes wrong in the suite without wasting time waiting for it to finish executing.

Now lets create the Jasmine XML report :

Now lets believe that things went well, how will you report this to other stakeholders ? how will you show the status of the last test execution?

The answer is to use the jasmine xml report:

Install it using npm:

npm i jasmine-reporters

Add the below line in conf.js

exports.config = {

onPrepare: function(){
//configure junit xml report
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
filePrefix: 'guitest-xmloutput',
savePath: '.'
}));
}
}
// so the xml file will be stored in current directory as guitest-xmloutput

Output:

Lets now create a HTML report

This report can’t be send to a Business analyst or any other non-tech guy right!!! lets add some visual treats using HTML.

The below npm tool takes the xml file we created in the previous section and converts it too HTML. The result will be stored in the current directory as ProtractorTestReport.html

The code gets browser name, version etc from the capabilities property, and the suite and test case name, from ‘describe’ and ‘it’ functions in spec.

You can install the tool through npm:

npm i protractor-html-reporter-2

Now add below code to conf.js

exports.config = {

onComplete: function() {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
platform = caps.get('platform');
var HTMLReport = require('protractor-html-reporter-2');
testConfig = {
reportTitle: 'Protractor Test Execution Report',
outputPath: './',
outputFilename: 'ProtractorTestReport',
screenshotPath: './screenshots',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: true,
testPlatform: platform
};
new HTMLReport().from('guitest-xmloutput.xml', testConfig);
});
},
}

Output:

Taking screenshots on failure:

you can take screen shot on test failures by using fs-extra, to install use below command:

npm i fs-extra

Now add below command to conf.js

exports.config = {

onPrepare: function(){
var fs = require('fs-extra');
fs.emptyDir('screenshots/', function (err) {
console.log(err);
});
jasmine.getEnv().addReporter({
specDone: function(result) {
if (result.status == 'failed') {
browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('screenshots/' + browserName + '-' + result.fullName+ '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
});
}
}
});
}
}

Screenshots will be taken and stored in ‘screenshots’ folder in the current directory.

Output:

Adding screenshots to html report:

Adding the above code to Onprepare property of protractor conf.js, ensures that on failure, screenshots are captured and stored on screenshots folder

The protractor-html tool will look for screenshots in this folder and add to the report automatically

output:

Final Config.js

exports.config = {
specs: ['spec.js'],
onPrepare: function(){
// Getting CLI report
      const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
}
}));

//Getting XML report
    var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
filePrefix: 'guitest-xmloutput',
savePath: '.'
}));
//Getting screenshots
  var fs = require('fs-extra');
fs.emptyDir('screenshots/', function (err) {
console.log(err);
});
jasmine.getEnv().addReporter({
specDone: function(result) {
if (result.status == 'failed') {
browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('screenshots/' + browserName + '-' + result.fullName+ '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
});
}
}
});
},
  onComplete: function() {
//Getting HTML report
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
platform = caps.get('platform');
var HTMLReport = require('protractor-html-reporter-2');
testConfig = {
reportTitle: 'Protractor Test Execution Report',
outputPath: './',
outputFilename: 'ProtractorTestReport',
screenshotPath: './screenshots',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: true,
testPlatform: platform
};
new HTMLReport().from('guitest-xmloutput.xml', testConfig);
});
}
}

Now lets see Loops and conditions in JavaScript

IF:

Syntax:
if (expression) {
Statement(s) to be executed if expression is true
}
Example:
let x = 5; 
if(x>4){
document.write(x)
}

ELSE:

Syntax:
if (expression) {
Statement(s) to be executed if expression is true
} else {
Statement(s) to be executed if expression is false
}
Example:
let x = 5; 
if(x>4){
document.write(x)
} else{
document.write("No");
}

ELSE IF:

Syntax:
if (expression 1) {
Statement(s) to be executed if expression 1 is true
} else if (expression 2) {
Statement(s) to be executed if expression 2 is true
} else if (expression 3) {
Statement(s) to be executed if expression 3 is true
} else {
Statement(s) to be executed if no expression is true
}
Example:
let x = 2; 
if(x>4){
document.write(x)
} else if (x>1){
document.write("No");
} else{
document.write("maybe")
}

Switch Case:

Syntax:
switch (expression) {
case condition 1: statement(s)
break;

case condition 2: statement(s)
break;
...

case condition n: statement(s)
break;

default: statement(s)
}
Example:
let a =1
let b= 4
switch (a+b){
case 2: document.write("2")
document.write("2 test")
break;
case 4: document.write("4")
document.write("4 test")
break;
case 5:
document.write("5")
document.write("5 test")
break;
default: document.write("invalid")
}

While Do:

Syntax:
while (expression) {
Statement(s) to be executed if expression is true
}
Example:
let a=5
while (a>0){
document.write(a+"W")
a--
}

Do While:

Syntax:
do {
Statement(s) to be executed if expression is true
} while (expression)
Example:
let a=5
do {
document.write(a+"W")
a--
} while (a>10)

For Loop:

Syntax:
for (initialization; test condition; iteration statement) {
Statement(s) to be executed if test condition is true
}
Example:
for(i=5; i>0;--i){
document.write(i)
}

For..in (Iterating through object with enumerable properties) :

This should be used only with objects that have elements stored as key value pairs, else if used with normal arrays, the index of the elements will be printed instead

Syntax:
for (variablename in object) {
statement or block to execute
}
Example:
var test= {a: 1, b: 2, c: 3}; 
var test2= [10,11,15]
for (a in test) {
document.write(a+"<br />");
// will print the key value of the elemnt (output is abc)
}
 for (a in test2) {
document.write(a+"<br />"); // will print 0,1,2 (index value)
}

For..of (Iterating through object) :

Syntax:
for (variablename of array) {
statement or block to execute
}
Example:
var test2= [10,11,15]
for (a of test2) {
document.write(a+"
"); // will print 10,11,15 (actual value)
}

Loop Control:

Continue, Break and label:

Continue:

  1. Continue keyword skips all the remaining code and navigates to next iteration
  2. Continue can be used only inside iterative blocks eg for, while , do..while , and for in, it cannot be used in switch and normal code block

In below code , document.write will be executed only if a!=1 , if a==1 , then the remaining code is skipped and the for loop goes to the next iteration.

Example:
let test=[1,2,3,4,6];
for (a in test) {

if(a==1){
continue;
}
document.write(a+"<br />"); // <br /> indicates next line
}

Break:

  1. Break is used to skip remaining code and iterations
  2. Once break is encountered, the code exists from the loop and continues with the outer code

The below code prints only 1 and 2, and on encountering 3, it exists from the loop and prints ‘exited’

Example:
let test=[1,2,3,4,6];
for (a in test) {
if(a==3){
break;
}
document.write(a+"<br />"); // <br /> indicates next line
}
document.write("exited");

Label:

  • Javascript allows controlling the continue and break code flow using labels
  • labels are used to identify loops or block and correctly specify which loop to break or continue
  • Any non reserved keyword could be used as label

In below code the inner loop is exited on getting a=3 and outer loop is broke when b=”c”

Here, we have labeled inner loop as inner and outer as outer.

Example:
let test=[1,2,3,4,6];
let test2=["a","b","c","d","e"];
outer:
for (b of test2){
inner:
for (a of test) {
if(a==3){
break inner;
}
if(b=="c"){
break outer;
}
document.write(a+ "<br />"); // indicates next line
}
document.write(b+ "<br />"); // indicates next line
}
document.write("exited");

You can use continue the same way to tell the loop to skip remaining lines and goto next iteration of the specified loop.

Example:
let test=[1,2,3,4,6];
let test2=["a","b","c","d","e"];
outer:
for (b of test2){
document.write(b+ "<br />"); // indicates next line
inner:
for (a of test) {
if(a==3){
continue outer;
}
if(b=="c"){
break outer;
}
document.write(a+ "<br />"); // indicates next line
}
}
document.write("exited");

Label could also be used with block

here we labeled the block ( code between { }) as foo, and in the second line we are existing this block so the third line within the block will not get executed.

foo: {
document.write('face'+"<br />");
break foo;
document.write('this will not be executed');
}
document.write('swap');

Lets begin with some highlevel JavaScript basics :)…

Java script simple statements could be ended without semi colon

Statements:

Both the below statements are valid

var a= 6;
var a=5

you could use ‘;’ semicolon to write multiple statement in single line

var1 =10;var 2=23;var 5= 9

Java script is case sensitive, meaning ‘Time’ and ‘time’ are two different elements.

Comments:

//single line comment
/* multi line statement
can be made like this */

html comment closing ‘ → ‘ is not detected by Javascript

Data Types:

Primitive:

JS following primitive data types:

  • Numbers — 1,2,3 ( Java script does not have separate representation for floating point and whole numbers, all the numeric are represented as floating points (Eg: 2.0)
  • Strings — “name”
  • Boolean — true or false

also supports ‘null’ and ‘undefined

Composite

JS also so support data type called ‘object

Declaring variables:

Variables are elements that store data and helps in re-usability

In JS , variables needs to be declared before it could be used. In JS , variable declaration could be made mainly using three keywords and are :

  1. var
  2. let
  3. const

Note: JS is dynamically typed (untyped) , meaning data type is detected dynamically. For instance, if for below variables , we store username = 1 and password = “we”; then the data type of username will be taken as Number and password as string.

Using Var

var username
var password

Multiple variable declaration in a single line is also permitted

var username,password,url

Note:

  • Variables declared with var are function scoped.
  • Could be modified
  • Could be re-declared ( It will replace the previous variable)
  • Does support hoisting (meaning that , if the variable is called before declaring , then JS will automatically declare and initialize it with value ‘undefined’)
console.log(username)
var username = "user"
// This prints "undefined" because java script changes this code internally as 
var username = undefined
console.log(username)
username = "user"
//This is called hoisting

Using let:

let username;

Note:

  • Variables declared with let are block scoped.
  • Could be modified
  • Could not be re-declared ( It will replace the previous variable)
  • Does not support hoisting. Variable should be declared before it could be used

Using const:

const username;

Note:

  • Variables declared with const are block scoped.
  • Could not be modified
  • Could not be re-declared ( It will replace the previous variable)
  • Does not support hoisting. Variable should be declared before it could be used

To know more read : ( Read : https://medium.com/@toddhd/javascript-understanding-the-difference-between-var-let-and-const-d0390da913 )

Variable Scope:

JavaScript only two scope :

  • Global — Available anywhere in the code
  • Local — Available only to the local function in which its defined

Variable naming rules:

Operators in JavaScript:

  • Arithmetic Operators

+ , — , * , / ,% , ++, —

  • Comparison Operators

==, !=, > , <, >=, <=,

  • Logical (or Relational) Operators

&& (AND) , || (OR), !

  • Assignment Operators

=, += (add and assign), -=, *= ,/=, %=

  • Conditional (or ternary) Operators

?:

eg: a==b? true:false

  • Bitwise Operators