undefined variable javascript code example

Example 1: javascript check for undefined

if (typeof myVariable === 'undefined'){
    //myVariable is undefined
}

Example 2: Undefined variable

@extends('layouts.app') @section('content') <h1>{{$post->title}}</h1> <p>{{$test}}</p>  @endsection

Example 3: js this returns undefined

function foo() {
    console.log(this);
}

// normal function call
foo(); // `this` will refer to `window`

// as object method
var obj = {bar: foo};
obj.bar(); // `this` will refer to `obj`

// as constructor function
new foo(); // `this` will refer to an object that inherits from `foo.prototype`

Tags:

Misc Example